-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSuper.java
More file actions
53 lines (49 loc) · 940 Bytes
/
Super.java
File metadata and controls
53 lines (49 loc) · 940 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
43
44
45
46
47
48
49
50
51
52
53
/*
TODO: Understand the concept and use of super.
"Super cannot be used from static block".
*/
class Parent
{
int a=10;
Parent()
{
System.out.println("Parent Constructor");
}
void parentMethod()
{
System.out.println("Parent Method");
}
}
class Child extends Parent
{
Child()
{
// Implicit invoke of super method
// super();
System.out.println("Child Constructor");
}
void childMethod()
{
System.out.println("Super can access Parent class variable a="+super.a);
super.parentMethod();
// invoking parent class method
System.out.println("Child Method");
}
}
class Call extends Child
{
public static void main(String[] args)
{
Call obj = new Call();
// implicit invoke of super
// super();
obj.callMethod();
}
void callMethod()
{
super.childMethod();
// super can invoke parent class method
super.parentMethod();
System.out.println("The above one invoked Parent from call");
}
}