Examveda
Examveda

Determine output of the following code.
interface A { }

class C { }

class D extends C { }

class B extends D implements A { }

public class Test extends Thread{
        public static void main(String[] args){
                B b = new B();
                if (b instanceof A)
                        System.out.println("b is an instance of A");
                if (b instanceof C)
                        System.out.println("b is an instance of C");
        }
}

A. Nothing.

B. b is an instance of A.

C. b is an instance of C.

D. b is an instance of A followed by b is an instance of C.

Answer: Option D


This Question Belongs to Java Program >> Interfaces And Abstract Classes

Join The Discussion

Comments ( 1 )

  1. Vinayak Kedia
    Vinayak Kedia :
    6 years ago

    yes

Related Questions on Interfaces and Abstract Classes

What is an interface in Java?

A. A contract specifying a set of methods that a class must implement

B. A class that cannot be instantiated

C. A class that contains only static methods

D. A subclass of the Object class