Java and Object-Oriented Programming Quiz

Test your knowledge of Java programming language features, object-oriented programming concepts, data types, operators, and compilation principles.

20 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

You have the following code in a file called Test.java class Base{ public static void main(String[] args){ System.out.println("Hello"); } } public class Test extends Base{} What will happen if you try to compile and run this?

  1. It will fail to compile.
  2. Runtime error
  3. Compiles and runs with no output.
  4. Compiles and runs printing "Hello"
Question 2 Multiple Choice (Single Answer)

What is the result of trying to compile and run the following code. public final static void main(String[] args){ double d = 10.0 / -0; if(d == Double.POSITIVE_INFINITY) System.out.println("Positive infinity"); else System.out.println("Negative infinity"); }

  1. output Positive infinity
  2. output Negative infinity
  3. Will fail to compile
  4. Runtime exception
Question 3 Multiple Choice (Single Answer)

What is the result that will be printed out ? void aMethod() { float f = (1 / 4) * 10; int i = Math.round(f); System.out.println(i); }

  1. 2
  2. 0
  3. 3
  4. 2.5
  5. 25
Question 4 Multiple Choice (Single Answer)

Which of the following are valid declarations?

  1. int i = 0XCAFE;
  2. boolean b = 0;
  3. char c = A;
  4. byte b = 128;
  5. char c = "A";
Question 5 Multiple Choice (Single Answer)

What is the result of trying to compile and run this program. public class Test{ public static void main(String[] args){ int[] a = {1}; Test t = new Test(); t.increment(a); System.out.println(a[a.length - 1]); } void increment(int[] i){ i[i.length - 1]++; } }

  1. Compiler error.
  2. Compiles and runs printing out 2
  3. Compiles and runs printing out 1
  4. An ArrayIndexOutOfBounds Exception at runtime
Question 6 Multiple Choice (Single Answer)

What will happen if you try to compile and run this ? public class Test{ static{ print(10); } static void print(int x){ System.out.println(x); System.exit(0); } }

  1. Compiler error.
  2. Will throw a NoSuchMethod error at runtime.
  3. It will compile and run printing out "10"
  4. It will run with no output.
  5. It will run and print "10" and then crash with an error.
Question 7 True/False

The following code is legal? long longArr[]; int intArr[] = { 7 ,8 , 9}; longArr = intArr;

  1. True
  2. False
Question 8 True/False

The range of a byte is from -127 to 128.

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

Identify the invalid assignments.

  1. float f = \u0038;
  2. long L2 = 2L;
  3. float f = 1.2;
  4. char c = '/u004E';
  5. byte b = 100;
Question 10 Multiple Choice (Single Answer)

What is the result of trying to compile and run the following code. public static void main(String[] args){ double d = 10 / 0; if(d == Double.POSITIVE_INFINITY) System.out.println("Positive infinity"); else System.out.println("Negative infinity"); }

  1. output Positive infinity
  2. output Negative infinity
  3. Will fail to compile
  4. Runtime exception
Question 11 Multiple Choice (Multiple Answers)

What attributes do all real world objects have?

  1. size and weight
  2. identity, state, and behavior
  3. state and behavior
  4. height and shape
Question 12 Multiple Choice (Multiple Answers)

What is another name for creating an object?

  1. initialization
  2. instantiation
  3. inheritance
  4. insubordination
Question 13 Multiple Choice (Single Answer)

String strA; String strB = new String("Cheese"); How many objects have been created in the above code snippet?

  1. 3
  2. 1
  3. 2
  4. 0
Question 14 True/False

Short-circuit parameters are && and ||

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

What is the name for an application changing a readable programming language into a machine-readable language?

  1. Encoder
  2. Converter
  3. Compiler
  4. Translator
Question 16 Multiple Choice (Single Answer)

Which class is the highest superclass of Java?

  1. root
  2. object
  3. stem
  4. minor
Question 17 Multiple Choice (Single Answer)

Overloading, overriding and dynamic method binding are three types of what?

  1. Inheritance
  2. Polymorphism
  3. Generalization
  4. Abstraction
Question 18 Multiple Choice (Single Answer)

What was the first language to bring together all the features that characterize an object-oriented programming system?

  1. C++
  2. Java
  3. SmallTalk
  4. C
Question 19 True/False

Setter is a special method, that sets property value. Used for private or protected variables or for some additional validation

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

Which of the following is not a C# keyword?

  1. a. if
  2. b. implements
  3. c. private
  4. d. delegates