Multi Level inheritance

Multi Level inheritance
  •  Subclass inherit from super class which inherit from another superclass
Multilevel level inheritance Example
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
 
class demo2
  {
	  int k=10;
	  void test()
	  {
		  System.out.println("running test method");
	  }
 
  }
 
  class Sample2 extends demo2
  {
	  double d=12.4;
	  void disp()
	  {
		  System.out.println("running disp method");
	  }
 
  }
 
 class Run2 extends Sample2
 {
	 boolean b=true;
	 void run()
	 {
		 System.out.println("running run method");
 
	 }
 
 }
 
public class MultiLevel
{
public static void main(String[] args)
{
 
	System.out.println("*****************************");
 
 
	Run2 r=new Run2();
 
	//run2 class have property of all class
 
	System.out.println("k value: "+r.k);
	r.test();
 
	System.out.println("d value: "+r.d);
	r.disp();
 
	System.out.println("b value: "+r.b);
	r.run();
 
 
	System.out.println("*****************************");
 
 
  }
 
}
 
output:
 
*****************************
k value: 10
running test method
d value: 12.4
running disp method
b value: true
running run method
*****************************

Leave a Reply

Your email address will not be published. Required fields are marked *