-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathThisAndSuper.java
52 lines (34 loc) · 1.26 KB
/
ThisAndSuper.java
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
class A extends Object{
// every class in java extends Object (class in java which has lot of methods) , even if don't mention
public A()
{
super();
System.out.println("in A");
}
public A(int n){
System.out.println("in A int");
}
}
class B extends A{
public B()
{ super();// call the constructor of the super class but default one
// and u want to call the parameterized constructor of the super class
// than pass the value in super
//every constructor in java has a method , which is there even if you don't mentionand that method is super
System.out.println("in B");
}
public B(int n){
// super(n);
this(); // this will execute the constructor of the same class
System.out.println("in B int");
}
}
public class ThisAndSuper {
public static void main(String a[]){
// B obj = new B();
// we have only created the object of class B , but constrector is callin for both A and B this means
// when u create a object of class it will call the constrector of subclass and superclass both
B obj = new B(10);
// i want to execute both constructor of B with one object so
}
}