-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThisSuper.java
More file actions
46 lines (31 loc) · 1.1 KB
/
ThisSuper.java
File metadata and controls
46 lines (31 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
46
class ThisSuper{
public static void main(String A[]) {
Derived dobj = new Derived();
dobj.gun();
}
}
class Base {
public int i;
public int j;
public Base(){
System.out.println(" Inside Base Constructor");
this.i = 11; // here, use of 'this' is optional
this.j = 21;
}
public void fun(){
System.out.println("Inside Base fun");
}
}
class Derived extends Base{
public int x;
public Derived(){
System.out.println(" Inside Derived Constructor");
this.x = 51; // use of this is optional
}
public void gun(){
System.out.println("Inside Derived gun");
System.out.println("Value of i = "+super.i); // Super - used to access form Base class
System.out.println("Value of j = "+super.j);
System.out.println("Value of x = "+this.x); // this - used to access from the same class as of the function we are calling
}
}