Java OCA OCP Practice Question 3252

Question

Consider the following program:

interface Printable { }

enum Letter implements Printable {       // IMPLEMENTS_INTERFACE
        A;//ww w .  ja v a 2 s.  c om
}

class Main {
        public static void main(String []args) {
                if(Letter.A instanceof Letter) {
                        System.out.println("yes, instance of Letter");
                }
                if(Letter.A instanceof Printable) {
                        System.out.println("yes, instance of Printable");
                }
                if(Letter.A instanceof Enum) {   // THIRD_CHECK
                        System.out.println("yes, instance of Enum");
                }
        }
}

Which one of the following options is correct?

a)       This program results in a compiler in the line marked with comment IMPLEMENTS_INTERFACE.

b)      This program results in a compiler in the line marked with comment THIRD_CHECK.

c)      When executed, this program prints the following:
     yes, instance of Letter/*ww  w.j a va2  s.co  m*/

d)      When executed, this program prints the following:
     yes, instance of Letter
     yes, instance of Printable

e)      When executed, this program prints the following:
     yes, instance of Letter
     yes, instance of Printable
     yes, instance of Enum


e)

Note

An enumeration can implement an interface (but cannot extend a class, or cannot be a base class).

Each enumeration constant is an object of its enumeration type.

An enumeration automatically extends the abstract class java.util.Enum. Hence, all the three instanceof checks succeed.




PreviousNext

Related