-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstraction.java
More file actions
57 lines (43 loc) · 954 Bytes
/
Abstraction.java
File metadata and controls
57 lines (43 loc) · 954 Bytes
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
package oops;
public class Abstraction {
public static void main(String[] args) {
BMW b1 = new BMW();
Audi a1 = new Audi();
b1.price = 70;
a1.price = 65;
b1.getPrice();
a1.getPrice();
b1.start();
a1.start();
b1.stop();
a1.stop();
}
}
class BMW extends Car{
@Override
void getPrice() {
System.out.println("Price of BMW Car : "+this.price);
}
@Override
void start() {
System.out.println("BMW is starting ....");
}
}
class Audi extends Car{
@Override
void getPrice() {
System.out.println("Price of Audi Car : "+this.price);
}
@Override
void start() {
System.out.println("Audi is starting .....");
}
}
abstract class Car{
public int price;
abstract void getPrice();
abstract void start();
void stop(){
System.out.println("Car is stopped now.");
}
}