Ask Question
17 November, 09:59

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. 17 November, 13:36
    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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers