Ask Question

Given the following code:

class C1 {}

class C2 extends C1 { }

class C3 extends C2 { }

class C4 extends C1 {}

C1 c1 = new C1 ();

C2 c2 = new C2 ();

C3 c3 = new C3 ();

C4 c4 = new C4 ();

Which of the following expressions evaluates to false?

c4 instanceof C2

c2 instanceof C1

c3 instanceof C1

c1 instanceof C1

+3
Answers (1)
  1. 20 April, 07:28
    0
    c4 instanceof C2 evaluates to false.

    Explanation:

    As C2 extends C1 so c2 instanceof C1 evaluates to true.

    As C3 extends C2 which then extends C1 so c3 instanceof C1 evaluates to true.

    As the object c1 is an instance of C1 class so c1 instanceof C1.

    Therefore only c4 instanceof C2 evaluates to false.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Given the following code: class C1 {} class C2 extends C1 { } class C3 extends C2 { } class C4 extends C1 {} C1 c1 = new C1 (); C2 c2 = 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