Single level inheritance

Single Level Inheritance
  •  In single level inheritance subclass inherit from only one super class
Single 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
 
class demo1
{
  int k=12;
 
  void test()
   {
     System.out.println("running test method");	
   }
 
}
 
class Sample1 extends demo1
{
   double d=12.4;
 
   void disp()
   {
    System.out.println("running disp method");	
   }
 
}
 
public class Singlelevel 
{
	public static void main(String[] args)
	{
 
     System.out.println("**********************");	
 
     Sample1 obj1=new Sample1();//now this object have property of both class
    //so using obj1 you can refer property of both class
 
    System.out.println("k value: "+obj1.k);
    obj1.test();
 
    System.out.println("d value: "+obj1.d);
    obj1.disp();
 
 
    System.out.println("**********************");	
 
  }
 
}
 
output:
 
**********************
k value: 12
running test method
d value: 12.4
running disp method
**********************

Leave a Reply

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