-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPolymorphism.java
More file actions
62 lines (55 loc) · 1.33 KB
/
Polymorphism.java
File metadata and controls
62 lines (55 loc) · 1.33 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
50
51
52
53
54
55
56
57
58
59
60
61
62
package com.java;
class Animalfamily{
public void sound(){
System.out.println("animal makes sound");
}
}
class bird extends Animalfamily{
public void sound() {
System.out.println("bird sound");
}
}
class cat_ extends Animalfamily{
public void sound() {
System.out.println("cat sound");
}
}
class shapes{
public double area(){
return 0;
}
}
class circle_shape extends shapes{
private int radius;
public circle_shape(int radius){
this.radius=radius;
}
public double area(){
return Math.PI*radius*radius;
}
}
class rectangle extends shapes{
private double len;
private double width;
public rectangle(double length,double width){
this.len=length;
this.width=width;
}
public double area(){
return len*width;
}
}
public class Polymorphism {
public static void main(String[] arg){
Animalfamily af = new Animalfamily();
af.sound();
bird b = new bird();
b.sound();
cat_ c = new cat_();
c.sound();
shapes s = new circle_shape(5);
System.out.println("area of circle :"+ s.area());
shapes s1 = new rectangle(2,2);
System.out.println("area of rectangle :"+ s1.area());
}
}