what fields and methods are inherited by which class in the following code publi
ID: 3536632 • Letter: W
Question
what fields and methods are inherited by which class in the following code
public class A
{
private int number;
protected String name;
public double price;
public A()
{
System.out.println("A()called");
}
private void foo1()
{
System.out.println("A version of foo1()called");
}
protected into foo2()
{
System.out.println("A version of foo2()called");
}
public String foo3()
{
System.out.println("A version of foo3()called");
return "Hi";
}
}
public class B extends A
{
private Char Services;
public B()
{
super();
system.out.println("B() called");
}
public void foo1()
{
System.out.println(B version of foo1()called");
}
protected int foo2()
{
int n = super.foo2();
System.out.println(B version of foo2()called");
return (n+5);
}
public String foo3()
{
String temp = super.foo3();
System.out.println(B version of foo3()called");
return (temp+"foo3");
}
}
public class C extends B
{
public C()
{
super();
System.out.println("C() called");
}
public void foo1()
{
System.out.println( "C version of foo1()called");
}
}
Explanation / Answer
protected String name;
public double price;
protected into foo2()
{
System.out.println("A version of foo2()called");
}
public String foo3()
{
System.out.println("A version of foo3()called");
return "Hi";
}
Above all are inherited by class B as well as class C
Following are inherited by class C only :
public void foo1()
{
System.out.println(B version of foo1()called");
}
protected int foo2()
{
int n = super.foo2();
System.out.println(B version of foo2()called");
return (n+5);
}
public String foo3()
{
String temp = super.foo3();
System.out.println(B version of foo3()called");
return (temp+"foo3");
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.