-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSuper_Method.java
More file actions
41 lines (27 loc) · 922 Bytes
/
Copy pathSuper_Method.java
File metadata and controls
41 lines (27 loc) · 922 Bytes
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
class A{
public A(){
super(); //By default it is present here implicitly
System.out.println("Default Constructor of A");
}
public A(int a){
super(); //By default it is present here implicitly
System.out.println("Parameterized Constructor of A");
}
}
class B extends A{
public B(){
super(3); //Parametrized constructor of A will be called
System.out.println("Default Constructor of B");
}
public B(int b){
this(); //It is used to call the default constructor of B
System.out.println("Parametrized Constructor of B");
}
}
public class Super_Method{
public static void main(String[] args){
// B b=new B(); //Default constructor of both the classes willbe called
// B b1=new B(2); //Default constructor of A and parametrized constructor of B will be called
B b2=new B(2);
}
}