-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLab6A.java
More file actions
65 lines (53 loc) · 1.31 KB
/
Lab6A.java
File metadata and controls
65 lines (53 loc) · 1.31 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
63
64
65
// 6A: Develop a Java program to create an abstract class named Shape. create three sub classes named Circle, Triangle and Square each
// class has 2 member functions named draw() and erase(). Demonstrate the use of polymorphism concept by developing suitable
// methods defining member data and main function.
abstract class Shape {
abstract void draw();
abstract void erase();
}
class Circle extends Shape {
void draw() {
System.out.println("Circle Created");
}
void erase() {
System.out.println("Circle Erased");
}
}
class Triangle extends Shape {
void draw() {
System.out.println("Triangle Created");
}
void erase() {
System.out.println("Triangle Erased");
}
}
class Square extends Shape {
void draw() {
System.out.println("Square Created");
}
void erase() {
System.out.println("Square Erased");
}
}
public class Lab6A {
public static void main(String[] args) {
Shape obj = new Circle();
obj.draw();
obj.erase();
obj = new Triangle();
obj.draw();
obj.erase();
obj = new Square();
obj.draw();
obj.erase();
}
}
/*
* Output:
* Circle Created
* Circle Erased
* Triangle Created
* Triangle Erased
* Square Created
* Square Erased
*/