Tag: programming languages

Questions Related to programming languages

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"); } } }

  1. Prints : "I am false interface" followed by " I am false String"

  2. Prints : "I am true interface" followed by " I am true String"

  3. Prints : "I am true interface" followed by " I am false String"

  4. Compile-time error


Correct Option: C

What will happen when you attempt to compile and run the following code? public class Static { static { int x = 5; } static int x,y; public static void main(String args[]) { x--; myMethod(); System.out.println(x + y + ++x); } public static void myMethod() { y = x++ + ++x; } }

  1. Compile-time error

  2. prints : 3

  3. prints : 1

  4. prints : 7


Correct Option: B