-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAAAAN_method2Overriding.java
More file actions
52 lines (43 loc) · 1.13 KB
/
AAAAN_method2Overriding.java
File metadata and controls
52 lines (43 loc) · 1.13 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
class A
{
public void start()
{
System.out.println("car A has started");
}
public void accelerate()
{
System.out.println("car A is accelerating");
}
public void changeGear()
{
System.out.println("gear of Car A has changed");
}
}
class B extends A
{
public void changeGear()
{
// method overriding
System.out.println("gear of Car B has changed");
}
public void openRoof()
{
System.out.println("open roof of car B");
}
}
public class AAAAN_method2Overriding {
public static void main(String arg[])
{
A car = new B(); // statement would create an instance(or object )of class B, which inherits all the properties
//and methods of class A in addition to its own. This is known as inheritance in object-oriented programming.
car.start();
car.accelerate();
car.changeGear();
System.out.println();
B car2 = new B();
car2.start();
car2.accelerate();
car2.changeGear();
car2.openRoof();
}
}