Java Programming Fundamentals
Test your knowledge of Java programming concepts including static methods, interfaces, inner classes, operators, and parameter passing.
Questions
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.
- True
- False
A static method can refer to any instance variable of the class.
- True
- False
Methods can be overloaded with a difference only in the type of the return variable.
- True
- False
All interface methods must be declared as public when implemented in a class.
- True
- False
All interface methods must be declared as public when implemented in a class.
- True
- False
A method in a class declared as static can only access static class members.
- True
- False
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); }
- Compilation error, attempting to perform binary comparison on logical data type.
- Compilation and output of "We are equal 10".
- Compilation and output of "Not equal! 20".
- Compilation and output of "Not equal! 10".
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)); } }
- prints: Value is - 9
- prints: Value is - 5
- Compilation error
- None of these
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. }
- a
- d
- c
- b