forked from rahulXbarnwal/JavaTutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCar.java
More file actions
35 lines (26 loc) · 1015 Bytes
/
Car.java
File metadata and controls
35 lines (26 loc) · 1015 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
package oops2;
// properties and behavior both will get inherited on extending
// When a class extends another class, it inherits all non-private fields and methods of the parent class, but constructors and private members are not inherited.
// Static methods are not truly inherited, they are hidden.
public class Car extends Vehicle {
String color;
void start() {
System.out.println(this); // oops2.Car@5b2133b1
System.out.println(this.model + " Car is starting");
}
Car () {
super(4);
System.out.println("Car is being created");
}
public static void main(String[] args) {
Car obj = new Car();
obj.wheelsCount = 4;
obj.model = "I10";
obj.color = "Red";
obj.start();
}
}
// every class in java extends Object Class
// when in multiple inheritance lets say A <-- B <-- C
// if C.start(), then it will check it in C first, if not present then B else A
// multilevel is possible, multiple inheritance is not