1class Car{
2 public Car()
3 {
4 System.out.println("Class Car");
5 }
6 public void vehicleType()
7 {
8 System.out.println("Vehicle Type: Car");
9 }
10}
11class Maruti extends Car{
12 public Maruti()
13 {
14 System.out.println("Class Maruti");
15 }
16 public void brand()
17 {
18 System.out.println("Brand: Maruti");
19 }
20 public void speed()
21 {
22 System.out.println("Max: 90Kmph");
23 }
24}
25class Maruti800 extends Maruti{
26
27 public Maruti800()
28 {
29 System.out.println("Maruti Model: 800");
30 }
31 public void speed()
32 {
33 System.out.println("Max: 80Kmph");
34 }
35 public static void main(String args[])
36 {
37 Maruti800 obj=new Maruti800();
38 obj.vehicleType();
39 obj.brand();
40 obj.speed();
41 }
42}
1Class X
2{
3 public void methodX()
4 {
5 System.out.println("Class X method");
6 }
7}
8Class Y extends X
9{
10public void methodY()
11{
12System.out.println("class Y method");
13}
14}
15Class Z extends Y
16{
17 public void methodZ()
18 {
19 System.out.println("class Z method");
20 }
21 public static void main(String args[])
22 {
23 Z obj = new Z();
24 obj.methodX(); //calling grand parent class method
25 obj.methodY(); //calling parent class method
26 obj.methodZ(); //calling local method
27 }
28}
1class Car{
2 public Car()
3 {
4 System.out.println("Class Car");
5 }
6 public void vehicleType()
7 {
8 System.out.println("Vehicle Type: Car");
9 }
10}
11class Maruti extends Car{
12 public Maruti()
13 {
14 System.out.println("Class Maruti");
15 }
16 public void brand()
17 {
18 System.out.println("Brand: Maruti");
19 }
20 public void speed()
21 {
22 System.out.println("Max: 90Kmph");
23 }
24}
25public class Maruti800 extends Maruti{
26
27 public Maruti800()
28 {
29 System.out.println("Maruti Model: 800");
30 }
31 public void speed()
32 {
33 System.out.println("Max: 80Kmph");
34 }
35 public static void main(String args[])
36 {
37 Maruti800 obj=new Maruti800();
38 obj.vehicleType();
39 obj.brand();
40 obj.speed();
41 }
42}