java program related to inheritance so it shows three numbers and display the sum
class A
{
int a;
int b;
void showab()
{
System.out.println(a+b);
}
}
class B extends A
{
int c;
void showc()
{
System.out.println(c);
}
}
class C extends B
{
int d;
public int sum()
{
d=a+b+c;
return d;
}
}
class add1
{
public static void main(String args[])
{
A obj1= new A();
B obj2= new B();
C obj3= new C();
obj1.a = 1;
obj1.b = 2;
obj3.a = 1;
obj3.b = 2;
obj1.showab();
obj2.c = 3;
obj3.c = 3;
obj2.showc();
obj3.sum();
System.out.println("sum is"+obj3.sum());
}
the output shows 3,3 and sum is 6
i want that output shows 1,2,3 and sum is 6 were my code is wrong
{
int a;
int b;
void showab()
{
System.out.println(a+b);
}
}
class B extends A
{
int c;
void showc()
{
System.out.println(c);
}
}
class C extends B
{
int d;
public int sum()
{
d=a+b+c;
return d;
}
}
class add1
{
public static void main(String args[])
{
A obj1= new A();
B obj2= new B();
C obj3= new C();
obj1.a = 1;
obj1.b = 2;
obj3.a = 1;
obj3.b = 2;
obj1.showab();
obj2.c = 3;
obj3.c = 3;
obj2.showc();
obj3.sum();
System.out.println("sum is"+obj3.sum());
}
the output shows 3,3 and sum is 6
i want that output shows 1,2,3 and sum is 6 were my code is wrong
0