1. Home
  2. Computing & Technology
  3. Computer Certification

Question 7

What will happen when you attempt to compile and run the following code?

interface MyInterface

{

}

public class MyInstanceTest implements MyInterface

{

            static String s;

            public static void main(String args[])

            {

                        MyInstanceTest t = new MyInstanceTest();

                        if(t instanceof MyInterface)

                        {

                                    System.out.println("I am true interface");

                        }

                        else

                        {

                                    System.out.println("I am false interface");

                        }

                        if(s instanceof String)

                        {

                                    System.out.println("I am true String");

                        }

                        else

                        {

                                    System.out.println("I am false String");

                        }

            }         

}

 

Compile time error

Runtime error
Prints : "I am true interface" followed by " I am true String"
Prints : "I am false interface" followed by " I am false String"
Prints : "I am true interface" followed by " I am false String"
Prints : "I am false interface" followed by " I am true String"

Back to beginning
| Next Question



Explore Computer Certification
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Computer Certification

©2009 About.com, a part of The New York Times Company.

All rights reserved.