-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInheritanceJava.java
More file actions
41 lines (40 loc) · 822 Bytes
/
Copy pathInheritanceJava.java
File metadata and controls
41 lines (40 loc) · 822 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
class Base{
int x;
public void setX(int x){
this.x=x;
}
public int getX(){
return x;
}
public Base(){
System.out.println("Im a Base constructor");
}
}
class Derived extends Base{
int y;
public void setY(int y){
this.y=y;
}
public int getY(){
return y;
}
public Derived(){
System.out.println("Im a Derived constructor");
}
}
class Derived2 extends Derived{
Derived2(){
System.out.println("I am a Derived2 constructor");
}
}
public class InheritanceJava
{
public static void main(String[] args) {
// System.out.println("Hello World");
Base b1 = new Base();
Derived b = new Derived();
Derived2 d = new Derived2();
b.setX(5);
System.out.println(b.getX());
}
}