-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathAbstractClasses.java
More file actions
59 lines (47 loc) Β· 1.14 KB
/
Copy pathAbstractClasses.java
File metadata and controls
59 lines (47 loc) Β· 1.14 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
package day8;
public class AbstractClasses {
public static void main(String[] args) {
// not possible
// GenericShape shape = new GenericShape();
GenericShape shape = new MyCircle(5);
GenericShape shape1 = new MyCircle(10);
doStuff(shape);
doStuff(shape1);
}
private static void doStuff(GenericShape shape) {
shape.draw();
shape.move(10, 10);
}
}
abstract class BasicBank {
abstract public double rateOfInterest();
}
class HDFC extends BasicBank {
@Override
public double rateOfInterest() {
return 6.5;
}
}
abstract class GenericShape {
int me = 10;
String property = "hello";
abstract void draw();
abstract void move(int x, int y);
public void hello() {
System.out.println("hello world");
}
}
class MyCircle extends GenericShape {
int radius;
MyCircle(int radius) {
this.radius = radius;
}
@Override
void draw() {
System.out.println("i am drawing circle : " + radius);
}
@Override
void move(int x, int y) {
System.out.println("moving to : " + x + " ; " + y);
}
}