-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest3.java
50 lines (48 loc) · 1011 Bytes
/
test3.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*import java.util.*;
class Shape{
public int area() {
return 0;
}
public int volume() {
return 0;
}
}
class Rectangle extends Shape{
private int w, h;
public Rectangle(int wp, int hp)
{
w=wp;
h=hp;
}
public int area(){return w*h;}
}
class Cube extends Rectangle
{
private int a;
public Cube(int ap)
{a=ap;}
public int area(){return 6*a*a;}
}
class test3
{
private static void caller(Shape s)
{
if(s instanceof Rectangle)
{
System.out.println(s.area());
}
if(s instanceof Cube)
{
System.out.println(s.volume());
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int w = sc.nextInt();
int h = sc.nextInt();
int a = sc.nextInt();
sc.close();
caller(new Rectangle(w, h));
caller(new Cube(a));
}
}*/