-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path27 Inheritance.txt
More file actions
45 lines (38 loc) · 696 Bytes
/
Copy path27 Inheritance.txt
File metadata and controls
45 lines (38 loc) · 696 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
// IS-A, HAS-A
class Calculator // Super
{
public int add(int i,int j)
{
return i+j;
}
}
class CalcAdv extends Calculator // Sub
{
// public int add(int i,int j)
// {
// return i+j;
// }
public int sub(int i,int j)
{
return i-j;
}
}
class CalcVeryAdv extends CalcAdv
{
public int multi(int i,int j)
{
return i*j;
}
}
public class InheritanceDemo
{
public static void main(String[] args)
{
CalcVeryAdv c1 = new CalcVeryAdv();
int result1 = c1.add(5, 4);
int result2 = c1.sub(6, 3);
int result3 = c1.multi(2, 3);
System.out.println(result1);
System.out.println(result2);
System.out.println(result3);
}