Java Programming Fundamentals

Test your knowledge of Java language fundamentals including collections, static methods, polymorphism, and compilation behavior.

13 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

try{ File f = new File("a.txt"); }catch(Exception e){ }catch(IOException io){ } Is this code create new file name a.txt ?

  1. True
  2. False
  3. Compile error
  4. none
Question 2 Multiple Choice (Single Answer)

What is the output for the below code ? public class A { int k; boolean istrue; static int p; public void printValue() { System.out.print(k); System.out.print(istrue); System.out.print(p); } } public class Test{ public static void main(String argv[]){ A a = new A(); a.printValue();

  1. 0 false 0
  2. 0 true 0
  3. 0 0 0
  4. Compile error - static variable must be initialized before use.
Question 3 Multiple Choice (Single Answer)

What is the output for the below code ? 1. public class Test { 2. public static void main(String... args) { 3. int [] index = new int[5]; 4. System.out.println(index instanceof Object); 5. } 6. }

  1. Compilation fails with an error at line 4
  2. Compilation fails with an error at line 3
  3. true
  4. false
Question 4 Multiple Choice (Single Answer)

If we do ArrayList lst = new ArrayList(); What is the initial capacity of the ArrayList lst ?

  1. 8
  2. 10
  3. none
  4. 0
Question 5 Multiple Choice (Single Answer)

HashMap can be synchronized by _______ ?

  1. Map m = Collection.synchronizeMap(hashMap);
  2. Map m = Collections.synchronizeMap(hashMap);
  3. Map m = hashMap.synchronizeMap();
  4. none
Question 6 Multiple Choice (Single Answer)

What is the output for the below code ? public class A { public void printValue(){ System.out.println("A"); } } public class B extends A { public void printValue(){ System.out.println("B"); } } 1. public class Test { 2. public static void main(String... args) { 3. A b = new B(); 4. newValue(b); 5. } 6. public static void newValue(A a){ 7. if(a instanceof B){ 8. ((B)a).printValue(); 9. } 10. } 11.}

  1. A
  2. Compilation fails with an error at line 4
  3. B
  4. Compilation fails with an error at line 8
Question 7 Multiple Choice (Single Answer)

What is the output for the below code ? 1. public class Test {2. int i=8; 3. int j=9; 4. public static void main(String[] args){ 5. add(); 6. } 7. public static void add(){ 8. int k = i+j; 9. System.out.println(k); 10. } 11. }

  1. Compilation fails with an error at line 5
  2. Compilation fails with an error at line 8
  3. 17
  4. 0
Question 8 Multiple Choice (Single Answer)

What does it print? public class CleverSwap { public static void main(String[] args) { int x = 1984; int y = 2001; x ^= y ^= x ^= y; System.out.println("x = " + x + "; y = " + y); } }

  1. x = 0; y = 1984
  2. x = 2001; y = 1984
  3. x = 2001; y = 0
  4. x = 1984; y = 2001
  5. x = 0; y = 0
  6. Error
Question 9 Multiple Choice (Single Answer)

What does it print ? /** * Generated by the IBM IDL-to-Java compiler, version 1.0 * from F:\TestRoot\apps\a1\units\include\PolicyHome.idl * Wednesday, June 17, 1998 6:44:40 o'clock AM GMT+00:00 */ public class Test { public static void main(String[] args) { System.out.print("Hell"); System.out.println("o world"); } }

  1. Hello world
  2. Won't even Compile
  3. Run time error
  4. None of these
Question 10 Multiple Choice (Single Answer)

What does this program do ? public class BrowserTest { public static void main(String[] args) { System.out.print("iexplore:"); http://www.google.com; System.out.println(":maximize"); } }

  1. Compilation Error
  2. iexplore::maximize
  3. Runtime Error
  4. None of these
Question 11 Multiple Choice (Single Answer)

What does this program do ? public class Null { public static void greet() { System.out.println("Hello world!"); } public static void main(String[] args) { ((Null) null).greet(); } }

  1. Hello world!
  2. Throw a NullPointerException
  3. Won't even compile
  4. Run time error
Question 12 Multiple Choice (Single Answer)

What does it print ? import java.util.*; public class NameGame { public static void main(String args[]) { Map<String, String> m = new IdentityHashMap<String, String>(); m.put("Mickey", "Mouse"); m.put("Mickey", "Mantle"); System.out.println(m.size()); } }

  1. Exception
  2. Stack Overflow
  3. 2
  4. 1
Question 13 Multiple Choice (Multiple Answers)

For a COBOL program -

  1. EXE is created for the called program and DLL is created for the calling program
  2. EXE is created for the calling program and DLL is created for the called program
  3. EXE is created for the both, called program and calling program
  4. DLL is created for the both, called program and calling program