-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathConstructor.java
More file actions
46 lines (38 loc) · 762 Bytes
/
Constructor.java
File metadata and controls
46 lines (38 loc) · 762 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
42
43
44
45
/*
Contructor:-
1-A constructor is a member function of a class which initializes objects of a class
2-Each class has a contructor (if user is not specifying any constructor JVM makes a constructor[ called default-constructor also-called No-argument constructor] for it during compilation )
3- Constructor declarations look like method declarations—except that they use the name of the class and have no return type.
*/
class A{
A(){
System.out.println("1");
}
}
class B extends A{
B(){
System.out.println("2");
}
B(int x){
this();
System.out.println(x);
}
}
class C extends B{
C(int y){
super(3);
System.out.println(y);
}
}
public class App1{
public static void main(String[] args) {
C c=new C(4);
}
}
/*
Output-
1
2
3
4
*/