Ask Question

Given the following classes and their objects:

class C1 {};

class C2 extends C1 {};

class C3 extends C1 {};

C2 c2 = new C2 ();

C3 c3 = new C3 ();

Analyze the following statement:

c2 = (C2) ((C1) c3);

a. c3 is cast into c2 successfully.

b. You will get a runtime error because you cannot cast

objects from sibling classes.

c. You will get a runtime error because the Java runtime

system cannot perform multiple casting in nested form.

d. The statement is correct.

+5
Answers (1)
  1. 31 January, 15:26
    0
    The answer is "Option b"

    Explanation:

    In the given code three-class C1, C2, and C3 are declared, in which C2 and C3 extend the class C1. In the next line, C2 and C3 object are created, that is c2 and c3. and in the last line c2 class object holds two-class C2, C1, and one object c3 value, this code will give runtime error because it can't cast object from sibling class, and wrong choices can be defined as follows:

    In option a, It is not correct because it can't cast c3 object into c2 object. In option c, It is not correct because it performs multiple casting in nested forms. In option d, It is wrong because the statement is not correct.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Given the following classes and their objects: class C1 {}; class C2 extends C1 {}; class C3 extends C1 {}; C2 c2 = new C2 (); C3 c3 = new ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers