Skip to main content

Super() method

What is the use of Super() Method in java ?
Whenever subclass inherit property of super class, subclass constructor should
make a call to the super class constructor either implicit(by compiler) or
explicit call is made by super() statement.
super() Method
  • super() Used to call super class constructor
  • super() Used inside constructor body only
  • It Must be first statement of constructor
  • Multiple super() statement not allowed
This is example of explicit constructor calling made by programmer using super()
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
 
package constructor;
 
 
 
class demo12
{
	demo12(int k)
	{
		System.out.println("running demo12 int arg constructor");
	}	
}
 
class Sample12 extends demo12
{
   Sample12(double d)
   {
 
           super(25);// call made to int arg constructor
	   System.out.println("running SAmple12 double arg constructor");
   }	
}
 
class Run12 extends Sample12
{
	Run12()
	{
		super(2.4); //call made to double arg constructor
		System.out.println("running Run12 constructor");
 
	}
 
}
 
 
public class ConstructorCallUsingSuper 
 
{
	public static void main(String[] args)
	{
 
		System.out.println("*****************************");	
		Run12 obj=new Run12();	
		System.out.println("*****************************");
 
	}
}
 
output:
*****************************
running demo12 int arg constructor
running SAmple12 double arg constructor
running Run12 constructor
*****************************