Java Programming Fundamentals

Test your knowledge of Java programming concepts including static methods, interfaces, inner classes, operators, and parameter passing.

9 Questions Published

Questions

Question 1 True/False

When an instance of a class, or object, is specified as a parameter to a method, a reference to the said object is passed to the method.

  1. True
  2. False
Question 2 True/False

A static method can refer to any instance variable of the class.

  1. True
  2. False
Question 3 True/False

Methods can be overloaded with a difference only in the type of the return variable.

  1. True
  2. False
Question 4 True/False

All interface methods must be declared as public when implemented in a class.

  1. True
  2. False
Question 5 True/False

All interface methods must be declared as public when implemented in a class.

  1. True
  2. False
Question 6 True/False

A method in a class declared as static can only access static class members.

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

What will happen when you attempt to compile and run the following code? int Output = 10; boolean b1 = false; if((b1 == true) && ((Output += 10) == 20)) { System.out.println("We are equal " + Output); } else { System.out.println("Not equal! " + Output); }

  1. Compilation error, attempting to perform binary comparison on logical data type.
  2. Compilation and output of "We are equal 10".
  3. Compilation and output of "Not equal! 20".
  4. Compilation and output of "Not equal! 10".
Question 8 Multiple Choice (Single Answer)

What results from attempting to compile and run the following code? public class Ternary { public static void main(String args[]) { int a = 5; System.out.println("Value is - " + ((a < 5) ? 9.9 : 9)); } }

  1. prints: Value is - 9
  2. prints: Value is - 5
  3. Compilation error
  4. None of these
Question 9 Multiple Choice (Single Answer)

Considering the following code, Which variables may not be referenced correctly at line 12? 1. public class Outer 2. { 3. public int a = 1; 4. private int b = 2; 5. public void method(final int c) 6. { 7. int d = 3; 8. class Inner 9. { 10. private void iMethod(int e) 11. { 12. 13. } 14. } 15. } 16. }

  1. a
  2. d
  3. c
  4. b