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}
1OOPs support the six different types of inheritance as given below :
2Single inheritance.
3Multi-level inheritance.
4Multiple inheritance.
5Multipath inheritance.
6Hierarchical Inheritance.
7Hybrid Inheritance.
1//Base Class
2class A
3{
4 public void fooA()
5 {
6 //TO DO:
7 }
8}
9
10//Base Class
11class B
12{
13 public void fooB()
14 {
15 //TO DO:
16 }
17}
18
19//Derived Class
20class C : A, B
21{
22 public void fooC()
23 {
24 //TO DO:
25 }
26}
27