-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSuperDemo.java
More file actions
45 lines (30 loc) · 983 Bytes
/
SuperDemo.java
File metadata and controls
45 lines (30 loc) · 983 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
class SuperDemo{
public static void main(String A[]) {
// Base bobj = new Base(11);
// bobj.fun();
Derived dobj = new Derived(); // ERROR
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(){
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);
}
}