-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConstructorTwist.java
More file actions
45 lines (33 loc) · 1.1 KB
/
Copy pathConstructorTwist.java
File metadata and controls
45 lines (33 loc) · 1.1 KB
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
//Constructor is not directly involve in the inheritance but
//when we create the child class object and the child class const. is called by JVM
//then we know that the first line of a const. is super() or this() so
//when child class const. is called then super(); is also called then --> the parent class
//const. is called automatically;
//Understand by the below example; and check the output
class ParentClass
{
// (4) Now this const. will called by the child class const.
ParentClass(){
System.out.println("Parent class Constructor");
}
void disp()
{
System.out.println("Parent method");
}
}
class Child extends ParentClass
{
/* (2) in this chld class I didn't declear any constructor so JVM will create a default const.
Child()
{
super(); // (3) from this super() the parent class const. will called and the
parent of this child class is ParentClass
}
*/
}
public class ConstructorTwist {
public static void main(String[] args) {
Child ch=new Child();//(1) Here Child class const. will called and then
ch.disp();
}
}