-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCarBmw.java
More file actions
47 lines (41 loc) · 1.09 KB
/
CarBmw.java
File metadata and controls
47 lines (41 loc) · 1.09 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
// ============================================
// Inheritance Example ~ BMW Car System
// Author ~ Vikas Kumar
// Topic ~ OOP ~ Inheritance ~ Polymorphism
// ============================================
// Parent class ~ Vehicle
class Vehicle {
// Base method ~ General vehicle info
public void info() {
System.out.println("BMW");
}
}
// Child class 1 ~ Inherits Vehicle
class Wheel extends Vehicle {
// Override ~ Wheel specific info
@Override
public void info() {
System.out.println("4 wheel");
}
}
// Child class 2 ~ Inherits Vehicle
class Colour extends Vehicle {
// Override ~ Colour specific info
@Override
public void info() {
System.out.println("Blue");
}
}
// Main class ~ Program starts here
class CarBmw {
public static void main(String[] args) {
// Creating objects
Vehicle v1 = new Vehicle();
Vehicle w1 = new Wheel();
Vehicle c1 = new Colour();
// Calling overridden methods
v1.info(); // Vehicle info
w1.info(); // Wheel info
c1.info(); // Colour info
}
}