-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleInheritance.java
More file actions
49 lines (41 loc) · 1.07 KB
/
Copy pathSimpleInheritance.java
File metadata and controls
49 lines (41 loc) · 1.07 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
49
/*************************************************************************
# File Name: SimpleInheritance.java
# Author:
# Mail:
# Created Time: 2016年11月12日 星期六 18时11分34秒
************************************************************************/
class A{
int i,j;
void showij(){
System.out.println("i and j :"+i+" "+j);
}
}
class B extends A{
int k ;
void showk(){
System.out.println("k : "+k);
}
void sum(){
System.out.println("i+j+k = "+(i+j+k));
}
}
public class SimpleInheritance{
public static void main(String args[]){
A superOb = new A();
B subOb = new B();
superOb.i = 10;
superOb.j = 20;
System.out.println("contents of superOb:");
superOb.showij();
System.out.println();
subOb.i = 7;
subOb.j = 8;
subOb.k = 9;
System.out.println("Contents of subOb:");
subOb.showij();
subOb.showk();
System.out.println();
System.out.println("Sum of i,j and k is ");
subOb.sum();
}
}