-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSingleInhEg.java
More file actions
74 lines (73 loc) · 1.37 KB
/
Copy pathSingleInhEg.java
File metadata and controls
74 lines (73 loc) · 1.37 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/** Example of Single inheritance */
class Ab
{
int a,b;
Ab() //No argumet constructor
{
a= 10;b=20;
}
Ab(int x,int y) //Parameaterised Constructor // Cosnstructot Overloading
{
a = x;b = y;
}
void ddisp() //Display Methoad
{
System.out.print("A = "+a+",B = "+b);
}
int sum()
{
return(a+b);
}
int sum(int x,int y) // methoad overloading
{
return(x+y);
}
}
class Abc extends Ab
{
int c;
Abc()
{
c = 30;
}
Abc(int x,int y,int z)
{
super(x,y);
c = z;
}
void disp() //Methoad overriding
{
Super.disp();
System.out.println(",C = "+c);
}
int sum()
{
return(super.sum()+c);
}
int sum(int x, int y, int z)
{
return(super.sum(x,y)+z);
}
}
class SingleInhEg
{
public static void main(String[] args)
{
Ab p = new Ab();
Ab q = new Ab(40,50);
Abc r = new Abc();
Abc s = new Abc(60,70,80);
p.disp();
System.out.println("Sum = "+p.sum());
System.out.println("Sum = "+p.sum(90,100));
q.disp();
System.out.println("Sum = "+q.disp());
System.out.println("sum = "+q.disp(110,120));
r.disp();
System.out.println("Sum = "+r.disp());
System.out.println("Sum = "+r.disp(130,140));
s.disp();
System.out.println("Sum = "+s.disp());
System.out.println("Sum = "+s.disp(150,160));
}
}