i cant run following program.can any one fix the problem public class helloApp{
ID: 3872816 • Letter: I
Question
i cant run following program.can any one fix the problem
public class helloApp{
public static void main(String[]args){
B b1 = new C(3,"one","Two");
}
}
public class B{
private String s;
public void setB(String s){
this.s = s;
}
public String gets(){
return s;
}
}
public class C extends B{
private int x;
private String a;
private String s;
public C(int x,String a,String s){
this.x = x;
this.a = a;
super (s);
s = "Five";
System.out.println("C:x is " + x);
System.out.println("C:a is " + a);
System.out.println("B:s is " + s);
//System.out.println("B:s is " + getS());
System.out.println("C:s is " + s);
}
}
Explanation / Answer
public class helloApp{
public static void main(String[]args){
B b1 = new C(3,"one","Two");
}
}
class B{
private String s;
public void B(String s)
{
this.s = s;
}
public String gets()
{
return s;
}
}
class C extends B
{
private int x;
private String a;
private String s;
public C(int x,String a,String s)
{
super.B (s);
this.x = x;
this.a = a;
s = "Five";
System.out.println("C:x is " + x);
System.out.println("C:a is " + a);
System.out.println("B:s is " + s);
//System.out.println("B:s is " + getS());
System.out.println("C:s is " + s);
}
}
output:
C:x is 3
C:a is one
B:s is Five
C:s is Five
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.