ANSWERS 2026/2027
Can you have static classes in Java? - ANSWER-Yes and no. You cannot have top-
level static classes, but you may have nested static classes (these are mainly used in
defining one-off, utility and/or library classes where instantiation would not make sense).
You can basically declare the class final to mimic static class behavior since you
wouldn't want to extend a static class in the first place.
ArithmeticException - ANSWER-Thrown by the JVM when code attempts to divide by
zero (Runtime Exception)
ArrayIndexOutOfBoundsException - ANSWER-Thrown by the JVM when code uses an
illegal index to access an array (Runtime Exception)
ClassCastException - ANSWER-Thrown by the JVM when an attempt is made to cast
an exception to a subclass of which it is not an instance (Runtime Exception)
IllegalArgumentException - ANSWER-Thrown by the programmer to indicate that a
method has been passed an illegal or inappropriate argument (Runtime Exception)
NullPointerException - ANSWER-Thrown by the JVM when there is a null reference
where an object is required (Runtime Exception)
NumberFormatException - ANSWER-Thrown by the programmer when an attempt is
made to convert a string to a numeric type but the string doesn't have an appropriate
format (Runtime Exception)
protected void finalize() - ANSWER-called by the garbage collector on an object when
garbage collection determines that there are no more references to the object (subclass
overrides the finalize method to dispose of system resources or to perform other
cleanup)
Method overloading - ANSWER-multiple methods with the same name but with a
different signature (keep in mind "public void buzz() { }" "buzz()" is the signature)
return type and all that other stuff can be different no problem
Calling this() in Java - ANSWER-this() must be the first line of a constructor if present
Variables declared inside an interface are? - ANSWER-Implicitly public static final (keep
in mind this is why the naming conventions will be like "LEFT_MOTOR")
, Functional Interfaces and lambda expressions - ANSWER-Interface must contain ONE
abstract method, lambda expressions here may be used to represent the instance of a
functional interface
Keep in mind lambda syntax!
Also, note that there must be the same number of arguments, as well as the type of
arguments that they specify. You don't need to specify types, but if you specify one, you
must specify the other. (aka (a,b) is good, but (String a, b) is NOT)
Switch statements - ANSWER-The value of the 'expression' in a switch-case statement
must be an integer, char, short, long. Float and double are not allowed.
StringBuilder s1 = new StringBuilder("meow");
if (s1.toString() == "meow") System.out.println("four"); - ANSWER-FALSE. While both of
them evaluate to "meow", they do not both point to the "meow" in the string pool.
What is the output when new Hippopotamus() is called?
1: class Mammal {
2: public Mammal(int age) { System.out.println("1"); }
3: }
4: public class Hippopotamus extends Mammal {
5: public Hippopotamus() { System.out.println("2"); }
6: } - ANSWER-THIS CODE WILL FAIL.
Keep in mind subclasses will make a call to the superclass if no explicit call is made to
the parent constructor. Therefore, super() will be run but there is nothing to receive it,
since public Mammal(int age) exists and a default constructor is not created.
Which of the following statements can be inserted in the blank so that the code will
compile successfully? - ANSWER-There have been a few of these trick questions, to be
honest. In this case, it doesn't seem like they want what would make sense from a
programmer's point of view, but literally as the question says, whatever would fool the
compiler.
Method overriding (subclasses) - ANSWER-Cannot be more restrictive than original
(private -> protected is fine, but not vice versa)
return types must be same or a subclass of original return type AND must have the
same parameters (different parameters is overloading!)
Can you pass a null reference? - ANSWER-A null value can always be passed as a
reference. Although this will compile without issue, it will produce a
NullPointerException at runtime. (LOOK AT QUESTION WORDING AND LOOK AT
WHAT THEY'RE ASKING FOR)
Can you make a method private and abstract? - ANSWER-No, there would be literally
no point to this method, as no class would be able to implement it.