Java Programming Fundamentals

Test your knowledge of core Java programming concepts including OOP, exceptions, garbage collection, data types, and AWT components.

20 Questions Published

Questions

Question 1 Multiple Choice (Multiple Answers)

What modifiers may be used with an interface declaration

  1. Public
  2. Private
  3. Abstract
  4. Protected
Question 2 True/False

The developer can force garbage collection by calling System.gc().

  1. True
  2. False
Question 3 Multiple Choice (Single Answer)

Assertions are used to enforce all but which of the following?

  1. Preconditions
  2. Postconditions
  3. Exceptions
  4. Class invariants
Question 4 Multiple Choice (Single Answer)

Which of the following keywords is used to invoke a method in the parent class?

  1. this
  2. super
  3. final
  4. static
Question 5 True/False

The following line of code is valid. int x = 9; byte b = x;

  1. True
  2. False
Question 6 Multiple Choice (Single Answer)

At first JAVA was named as______ .

  1. Fusion
  2. Gabriel
  3. Oak
  4. Globe
Question 7 True/False

A lock can be acquired in a class.

  1. True
  2. False
Question 8 True/False

Garbage collection guarantee that a program will not run out of memory.

  1. True
  2. False
Question 9 Multiple Choice (Multiple Answers)

What is the purpose of the Runtime class?

  1. To provide access to the Java runtime system.
  2. To avoid run time exception.
  3. To provide the capability to execute code no matter whether or not an exception is thrown or caught.
  4. Both 2 & 3
Question 10 Multiple Choice (Single Answer)

Which containers may have a MenuBar?

  1. Panel
  2. Frame
  3. Class
  4. JVM
Question 11 True/False

Can a Byte object be cast to a double value?

  1. True
  2. False
Question 12 True/False

A class inherit the constructors of its superclass?

  1. True
  2. False
Question 13 Multiple Choice (Single Answer)

Which abstract class is the super class of all classes used for writing characters. Select the one correct answer.

  1. FileWriter
  2. CharWriter
  3. Writer
  4. OutputStream
  5. FileOutputStream
Question 14 Multiple Choice (Single Answer)

Checked Exceptions are

  1. all sub-classes of Throwable
  2. not the sub classes of RuntimeException
  3. all sub-classes of Error
  4. None of these
Question 15 Multiple Choice (Single Answer)

Which class is the immediate superclass of the Container class?

  1. Frame
  2. Component
  3. Public
  4. Super
Question 16 Multiple Choice (Single Answer)

class test{} class tester extends test{ public static void main(String[] args) { test t1 = new tester(); test t2 = new test(); tester t3 = new tester(); System.out.println( t1 instanceof tester); System.out.println( t2 instanceof tester); System.out.println( t3 instanceof tester); System.out.println( t1 instanceof test); System.out.println( t2 instanceof test); System.out.println( t3 instanceof test); }

  1. True False True True True True
  2. True False False True True True
  3. True False True True True False
  4. True False True True False True
Question 17 Multiple Choice (Single Answer)

public class Fun { public static void main(String[] args){ int x=0; boolean b=true; String str; str=(b)?"success": (x=0)?"Failure":"Neither"; System.out.println(str); } }

  1. Failure
  2. success
  3. Exception will be thrown
  4. Compilation error
  5. Neither
Question 18 Multiple Choice (Single Answer)

class Root { int bark=10; public void get(){ System.out.println("Root"); } } public class Tree extends Root{ public void get(){ bark =15; System.out.println("Tree"); } public static void main(String[] args){ Tree t = new Tree(); Root r = new Root(); Root t1= new Tree(); r.get(); t.get(); t1.get(); System.out.println(t.bark); System.out.println(t1.bark); System.out.println(r.bark); } }

  1. Root Tree Tree 15 15 15
  2. Root Tree Tree 10 15 15
  3. Root Tree Root 15 15 10
  4. Root Tree Tree 15 15 10
  5. Root Tree Tree 15 10 10
Question 19 Multiple Choice (Single Answer)

public class Top { private int i; Top(int i) {this.i=i; } public int getValue(){ return this.i; } } class Bottom{ public static void main(String[] args) { Top tp = new Top(5); String j = Integer.toString(tr.getValue()); tp.i=15; System.out.println( tp.i + j); } }

  1. 155
  2. Compilation error
  3. Exception
  4. 20
  5. 5 5
Question 20 Multiple Choice (Single Answer)

public class Play { public static void main(String[] args) { int[][] a = {{5,2,4,7}, {9,2}, {3,4}}; int[] b = a[1]; int[][] b1= new int[3][]; int a2 = b[2]; System.out.println(a2); } }

  1. 2
  2. 4
  3. Exception
  4. Compilation error
  5. 9