-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSuperDemo2.java
More file actions
48 lines (31 loc) · 1.1 KB
/
SuperDemo2.java
File metadata and controls
48 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
47
48
class SuperDemo2{
public static void main(String A[]) {
// Base bobj = new Base(11);
// bobj.fun();
Derived dobj = new Derived();
dobj.gun();
}
}
class Base {
public int i;
public Base(int no){
System.out.println(" Inside Base Constructor");
this.i = no; // here, use of 'this' is optional
}
public void fun(){
System.out.println("Inside Base fun");
}
}
class Derived extends Base{
public int i;
public Derived(){
super(11); // Explicit call to Base Constructor , can cause error if its not on the first line (error depends on version of java)
System.out.println(" Inside Derived Constructor");
this.i = 21; // use of this is optional
}
public void gun(){
System.out.println("Inside Derived gun");
System.out.println("Value of i = "+i);
System.out.println("Value of i from Base = "+super.i);
}
}