-
Notifications
You must be signed in to change notification settings - Fork 0
/
Example_for_polymorphism.java
54 lines (54 loc) · 1.27 KB
/
Example_for_polymorphism.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
51
52
53
54
/*a program to create a class named shape. In this class we have three sub
classes circle, triangle and square each class has two member function named draw ()
and erase (). Create these using polymorphism concepts */
class shape{
void draw(int n){
System.out.println("Shape drawn");
}
void erase(int n){
System.out.println("Shape erased");
}
}
class circle extends shape{
void draw(){
System.out.println("Circle drawn");
}
void erase(){
System.out.println("Circle erased");
}
}
class triangle extends shape{
void draw(){
System.out.println("Triangle drawn");
}
void erase(){
System.out.println("Triangle erased");
}
}
class square extends shape{
void draw(){
System.out.println("Square drawn");
}
void erase(){
System.out.println("Square erased");
}
}
class Example_for_polymorphism{
public static void main(String[] args){
circle c=new circle();
c.draw();
c.erase();
c.draw(1);
c.erase(1);
triangle t=new triangle();
t.draw();
t.erase();
t.draw(1);
t.erase(1);
square s=new square();
s.draw();
s.erase();
s.draw(1);
s.erase(1);
}
}