Skip to content

Commit c16c33d

Browse files
committed
Abstraction Demo
1 parent b22e191 commit c16c33d

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

AbstractionDemo1.java

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
abstract class Shape{
2+
abstract void draw();
3+
public void paint(){
4+
System.out.println("rainbow...");
5+
}
6+
}
7+
class Rectangle extends Shape{
8+
public void draw(){
9+
System.out.println("Draw a rectangle...");
10+
}
11+
}
12+
class Circle extends Shape{
13+
public void draw(){
14+
System.out.println("Draw a circle...");
15+
}
16+
}
17+
class AbstractionDemo1{
18+
public static void main(String[] args){
19+
Shape shape = new Rectangle();
20+
shape.draw();
21+
shape.paint();
22+
shape = new Circle();
23+
shape.draw();
24+
}
25+
}

AbstractionDemo2.java

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
interface Shape{
2+
void draw();
3+
public static void paint(){
4+
System.out.println("rainbow...");
5+
}
6+
}
7+
class Rectangle implements Shape{
8+
public void draw(){
9+
System.out.println("Draw a rectangle...");
10+
}
11+
}
12+
class Circle implements Shape{
13+
public void draw(){
14+
System.out.println("Draw a circle...");
15+
}
16+
}
17+
class AbstractionDemo2{
18+
public static void main(String[] args){
19+
Shape shape = new Rectangle();
20+
shape.draw();
21+
Shape.paint();
22+
shape = new Circle();
23+
shape.draw();
24+
}
25+
}

0 commit comments

Comments
 (0)