Review Flashcards
What type does the Integer.parseInt method return?
Primitive integer (int)
What type does the Integer.valueOf method return?
Integer object
What does the ArrayList set( ) method do?
Sets an element at the index provided to the value provided
In Java, forward references to local variables are not allowed.
True
If a variable is declared in a switch statement case, it is available to all cases after it, but not before it.
True
Only a String, byte, short, int or char can be used as types of a switch variable.
False, the wrapper classes of these primitives can also be used.
You can start a literal value with an underscore.
False
A literal is a fixed value that doesn’t need further calculations in order for it to be assigned to any variable.
True
The char data type can be assigned a positive or a negative integer.
False, char is unsigned, it can only be assigned a positive integer value.
A top level class cannot be defined with the private or protected access modifier.
True
A concrete class cannot define an abstract method.
True
Local variables can be defined with access modifiers.
False
The append( ) method adds a String to the end of a String object.
False, the append( ) method belongs to StringBuilder.
Variables local to an if block are accessible to any else if or else blocks that follow it as well.
False
static public final void jump( ) { } is a valid method.
True
String static public jump( ) is a valid method
False, the return type is out of place.
public static void 2test ( ) { } is a valid method
False, you cannot start an identifier with a number.
Method arguments are the variables that appear in the definition of a method.
False, method arguments are the actual values that are passed to a method.
Static methods can access the nonstatic variables and methods of a class.
False.
To import the static method sort( ) from the Collections class, you would use the statement import static java.util.Collections;
False, static imports are only able to import static members, so import static java.util.Collections.*; or import static java.util.Collections.sort would be valid.
When a constructor is given the private access modifier, the class cannot be instantiated except for within itself.
True
When calling this( ) in a constructor, it can be placed anywhere in the constructor.
False, this( ) must be the first statement in any constructor that is calling it.
Java supports multiple inheritance of type, but not multiple inheritance of state.
True
The Java compiler will not ignore extra semicolons.
False, it does ignore extra semicolons.
In Java, autoboxing/unboxing is preferred over widening a variable.
False, widening is preferred over autoboxing/unboxing.
The order of initialization in a Java class is static variables/initializers, superclass, constructor, then instance variables/initializers.
False, the order of initialization is superclass, static variables/initializers, instance variables/initializers, and constructors.
Abstract methods cannot be declared private or final.
True.
Abstract methods can be defined in concrete classes.
False, abstract methods can only be defined in abstract classes.
An abstract method can be defined as static.
False, abstract methods cannot be defined as static.
Variables in an interface are implicitly public, static and final.
True.
Methods in an interface are implicity abstract and public.
True.
An interface method cannot be static.
False, it can be static as long as it has a body.
An interface method cannot be defined as protected.
True.
An interface method can be declared as private as long as the method has a body.
True.
Interfaces inherit from java.lang.Object.
False, only classes inherit java.lang.Object.
A method defined with the final modifier can be overridden as long as the method has the same parameters.
False, final methods cannot be overridden.
Checked exceptions are subclasses of the Exception class.
True.
You are required to handle Unchecked Exceptions.
False
Throwable is a subclass of the Exception class.
False, it is a super class of Exception.
IOException is a subclass of …
Exception
SecurityException is a subclass of …
RuntimeException
ClassCastException is a subclass of …
RuntimeException
NullPointerException is a subclass of …
RuntimeException
IndexOutOfBoundsException is a subclass of …
RuntimeException
You can override a parent class static method with a non-static method of the same name and parameters in its subclass.
False, you cannot override a static method with a non static method, and vice versa.
Variables can be defined as abstract.
False
You can concatenate a char with a String without casting.
True
The wrapper classes of the primitive data types are mutable.
False, they are immutable, but using operators on them that change them, like ++ or –, will return an object with the new value to the reference.
All interface variables are considered public, static, and final, even if not declared as such.
True.
The compiler checks the validity of a call on a reference variable by looking at the declared class of that reference.
True.