-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path15_this-super keyword in java
69 lines (60 loc) · 1.64 KB
/
15_this-super keyword in 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Inheritance using super keyword
//package com.company;
//
//class Base1{
// Base1(){
// System.out.println("I am a constructor");
// }
// Base1(int x){
// System.out.println("I am an overloaded constructor with value of x as: " + x);
// }
//}
//class Derived1 extends Base1{
// Derived1(){
// //super(0);
// System.out.println("I am a derived class constructor");
// }
// Derived1(int x, int y){
// super(x);
// System.out.println("I am an overloaded constructor of Derived with value of y as: " + y);
// }
//}
//
//class ChildOfDerived extends Derived1{
// ChildOfDerived(){
// System.out.println("I am a child of derived constructor");
// }
// ChildOfDerived(int x, int y, int z){
// super(x, y);
// System.out.println("I am an overloaded constructor of Derived with value of z as: " + z);
// }
//}
//public class Inheritance {
// public static void main(String[] args) {
// // Base1 b = new Base1();
// // Derived1 d = new Derived1();
// // Derived1 d = new Derived1(14, 9);
// // ChildOfDerived cd = new ChildOfDerived();
// ChildOfDerived cd = new ChildOfDerived(12, 13, 15);
// }
//}
// Inheritance using this keyword
package com.company;
class Ekclass{
int a;
public int getA() {
return a;
}
Ekclass(int v){
this.a=v;
}
public int returnone(){
return 1;
}
}
public class this_super {
public static void main(String[] args) {
Ekclass e = new Ekclass(4);
System.out.println(e.getA());
}
}