Answer to Question #287547 in Java | JSP | JSF for Saphira

Question #287547
  1. Find the statement that causes the compilation error.
  2. Determine the output if that statement is removed.



Class A {

public voit test () {

System.out.print("A");

}

}

Class B extends A {

public void test () {

System.out.print("B");

}

}








public class C extends A {

public void test () {

System.out.print("C");

}

public static void main (String [] args) {

A b1 = new A ();

A b2 = new C ();

b1 = (A) b2;

A b3 = (B) b2;

b1.test ();

b2.test ();

}

}


1
Expert's answer
2022-01-14T04:36:06-0500
class A {


	public void test() {


		System.out.print("A");


	}


}


class B extends A {


	public void test() {


		System.out.print("B");


	}


}


class C extends A {


	public void test() {


		System.out.print("C");


	}
}
class App{
	public static void main(String[] args) {
		A b1 = new A();
		A b2 = new C();
		b1 = (A) b2;
		b1.test();


		b2.test();


	}


}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog