-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstractClass.java
More file actions
49 lines (49 loc) · 1.44 KB
/
Copy pathAbstractClass.java
File metadata and controls
49 lines (49 loc) · 1.44 KB
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
// abstract class Super{
// public Super(){System.out.println("super constructor");}
// public void meth1(){System.out.println("meth1");}
// abstract public void meth2();}
// class Sub extends Super{
// public void meth2(){System.out.println("meth2");}
// }
// public class AbstractClass {
// public static void main(String[] args) {
// Super s=new Sub();
// s.meth1();
// s.meth2();
// }
// }
abstract class shape{
abstract double perimeter();
abstract double area();}
class circle extends shape{
double radius;
public double perimeter(){
return 2*Math.PI*radius;}
public double area(){
return Math.PI*radius*radius;}}
class rectangle extends shape{
double length;double breadth;
public double area(){
// length=l;breadth=b;
return length*breadth;}
public double perimeter(){
return 2*(length+breadth);
}
}
public class AbstractClass{
public static void main(String[] args) {
circle c=new circle();
c.radius=2;
System.out.println(c.perimeter());
System.out.println(c.area());
rectangle r=new rectangle();
r.length=1;
r.breadth=2;
System.out.println(r.area());
System.out.println(r.perimeter());
shape s=c;
System.out.println(s.area());
shape S=r;
System.out.println(S.area());
}
}