-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConstructorTwist2.java
More file actions
64 lines (51 loc) · 1.06 KB
/
Copy pathConstructorTwist2.java
File metadata and controls
64 lines (51 loc) · 1.06 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
class Parentt
{
int a,b;
Parentt()
{
a=10;
b=20;
System.out.println("Parent class constructor executed!");
}
Parentt(int a,int b)
{
this.a=a;
this.b=b;
System.out.println("Parent class constructor executed!");
}
}
class Childd extends Parentt
{
int x,y;
Childd()
{
x=100;
y=200;
System.out.println("Child class constructor executed!");
}
Childd(int x,int y)
{
//in this case also JVM call only super() but if you want to execute the para const.
//of parent call then we have to pass some argu. to the super(argu1,argu2) to call the
//para const. and we have to call it explicitly
super(x,y);
this.x=x;
this.y=y;
System.out.println("Child class constructor executed!");
}
void disp()
{
System.out.println(a);
System.out.println(b);
System.out.println(x);
System.out.println(y);
}
}
public class ConstructorTwist2 {
public static void main(String[] args) {
Childd c=new Childd();
c.disp();
Childd c2=new Childd(1000,2000);
c2.disp();
}
}