forked from ParthMurge/Java-Codes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcwh_47_this_super.java
More file actions
42 lines (32 loc) · 879 Bytes
/
cwh_47_this_super.java
File metadata and controls
42 lines (32 loc) · 879 Bytes
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
package company;
class EkClass
{
int a;
int getA() {
return a;
}
EkClass(int a) {
this.a = a; // "this" is a way for us to refer an object of the class which is being created/referenced.
}
public int meth(int a) {
return a;
}
}
class DoClass extends EkClass {
DoClass(int a) {
super(a);
/* super --> a reference variable used to refer immediate parent class object.
* - can be used to refer immediate parent class instance variable.
* - can be used to invoke parent class methods.
* - can be used to invoke parent class constructor.
*/
System.out.println("I am a constructor.");
}
}
public class cwh_47_this_super {
public static void main(String[] args) {
EkClass e = new EkClass(6);
DoClass d = new DoClass(45);
System.out.println(e.getA());
}
}