Ask Question

Which of the following expressions evaluates to false?

class C1 {}

class C2 extends C1 { }

class C3 extends C2 { }

class C4 extends C1 {}

C1 c1 = new C1 ();

C1 c2 = new C2 ();

C1 c3 = new C3 ();

C1 c4 = new C4 ();

c1 instanceof C1

c2 instanceof C1

c4 instanceof C2

c3 instanceof C1

+4
Answers (1)
  1. 27 June, 15:02
    0
    If we analyze the given piece of code, C1, C2, C3 and C4 are 4 classes.

    C1 is the base class and does not derive from any other class. C2 is a class which inherits C1. C3 is a class which inherits C2 and indirectly inherits from C1. C4 is a class which inherits C1 directly. If analyses the instance creation statement,

    c1 instance of C1 is valid because the object is created for class C1.

    c1 c2 = new C2 () is valid once again the object is created for Class C2

    c1 c3 = new C3 () is invalid because the class C3 directly inherits from C2 and not from C1

    c1 c4 = new C4 () is valid
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Which of the following expressions evaluates to false? class C1 {} class C2 extends C1 { } class C3 extends C2 { } class C4 extends C1 {} ...” 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