Access over 20 million homework & study documents

4 Assume that c is a reference of type C that refers to an object o

Content type
User Generated
Rating
Showing Page:
1/2
4. Assume that c is a reference of type C that refers to an
object of type E. If D is a superclass class of E, what
happens with the code below?
D d = (D) c; ?
a. runtime error
b. runs fine
Solution
The answer for your question is option a that is,runtime
error.
Reason:Code for the above question is as below:
class C{
public void C(){
System.out.println(\"This is class C\");
}
}
class D{
public void D(){
System.out.println(\"This is class D\");
}
}
class E extends D{

Sign up to view the full document!

lock_open Sign Up
Showing Page:
2/2

Sign up to view the full document!

lock_open Sign Up
Unformatted Attachment Preview
4. Assume that c is a reference of type C that refers to an object of type E. If D is a superclass class of E, what happens with the code below? D d = (D) c; ? a. runtime error b. runs fine Solution The answer for your question is option a that is,runtime error. Reason:Code for the above question is as below: class C{ public void C(){ System.out.println(\"This is class C\"); } } class D{ public void D(){ System.out.println(\"This is class D\"); } } class E extends D{ public void E(){ System.out.println(\"This is class E\"); } } public class HelloWorld{ public static void main(String []args ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Anonymous
Excellent! Definitely coming back for more study materials.

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4