OCA Flashcards
Can you redeclare variables in the initialization block of the for loop?
No
Can you use more datatypes in the initialization block of a for loop?
No
Are immutable classes final or not?
They are final
What happens with strings that are not in the string pool(they are not literals, hence, were created using “new”) when they are no longer used?
They are garbage collected, just like any other object
True or false: Varargs are always allowed in place of an array
True
What kind of operators can & have?
Integral and boolean
What does this code block print?
Class.forName(“not_a_real_class”)
ClassNotFoundException
What objects types can be caught (as Exceptions)?
All Throwable instances
What datatypes can be used as switch variables?
String, byte, char, short, int + their Wrappers, enum
True or false: a switch can contain two or more identical cases
False
Are java.time package classes mutable or immutable?
Immutable
True or false: you can create arrays of any type, with length zero
True
True or false: subclasses can define methods with the same signature as the private methods in the base class. Justify.
True (since private methods are not inherited)
True or false: polymorphism applies to both static and non-static methods.
False. When applied to static methods, it is called ‘method hiding’
Does an assigment executed inside the condition of a conditional block alter the assigned variable permanently?
Yes
Can a subclass override the superclass’ constructors? Justify
No, because constructors are NOT inherited
True or false: Any type of class can implement any interface
True
True or false: Any class(abstract/concrete) can extend any class
True
True or false: Native methods cannot be abstract
True
True or false: String, StringBuilder and StringBuffer cannot be extended. Justify.
True, because they are final
On what types of operands does % work?
Both integral and floating point
On what types of operands do !, && and || work?
Boolean
On what types of operands does ~(bitwise complement) work?
Only on integral types
True or false: A short variable can never be assigned to a char without explicit casting
True