JAVA Flashcards
A checked exception must be handled by the developer.
Select one:
a. True
b. False
True
1) Checked: are the exceptions that are checked at compile time.
2) Unchecked are the exceptions that are not checked at compile time.
A class can extend multiple interfaces.
Select one:
a. True
b. False
False
A class can implement more than one interface at a time.
A constructor Select one: a. Can be overloaded b. Has a return type c. Has to exist in the source for a class.
a. Can be overloaded
Constructor name must be same as its class name Constructor must have no explicit return type
A final class Select one: a. Must contain an abstract method b. Has immutable attributes c. Cannot be extended d. Cannot extend a class
c. Cannot be extended
A final class can be instantiated but not extended (subclassed).
A List extends Collection to handle sets, which must contain unique elements
Select one:
a. True
b. False
b. False
A Set cannot contain duplicate elements while a List can.
A static method can
Select one:
a. Cannot be overloaded
b. Can only be called if at least one instance of its class exists in the program
c. Be called even if no instances of its class exist in the program
d. Only be called from a static method
c. Be called even if no instances of its class exist in the program
A static method belongs to the class rather than object of a class. A static method can be invoked without the need for creating an instance of a class. Static method can access static data member and can change the value of it.
A sub class can access private members of the super class
Select one:
a. False
b. True
a. False
Private members (both fields and methods) are only accessible inside the class they are declared or inside inner classes.
A subclass can access its parent class’s private attributes.
Select one:
a. True
b. False
b. False
If a data member within a class is declared as private, then it is only accessible from within that same class, nested classes in the same file and access via reflection.
A try block must have a catch block
Select one:
a. True
b. False
b. False
If any of the code in the try block can throw a checked exception, it has to appear in the throws clause of the method signature. If an unchecked exception is thrown, it’s bubbled out of the method.
An anonymous class inherits directly from Object.
Select one:
a. False
b. True
a. False
An anonymous inner class is an inner class that is declared without using a class name at all – and that of course is why it’s called an anonymous class.
An EOFException catch block can be coded after an IOexception catch block.
Select one:
a. True
b. False
b. False
EOFException extends IOException
EOF = End of File
IO = Input Output
An interface can extend another interfaces.
Select one:
a. True
b. False
a. True
Arrays are static whereas ArrayLists are dynamic.
Select one:
a. False
b. True
b. True
Array: Simple fixed sized arrays that we create in Java
ArrayList : Dynamic sized arrays in Java that implement List interface
Bytecode is written in binary.
Select one:
a. False
b. True
a. False
Bytecode is the compiled format for Java programs. Once a Java program has been converted to bytecode, it can be transferred across a network and executed by Java Virtual Machine (JVM)
Code inside of a finally block will always be run if its try block has been entered.
Select one:
a. False
b. True
a. False
If the JVM exits while the try or catch code is being executed, then the finally block may not execute. Likewise, if the thread executing the try or catch code is interrupted or killed, the finally block may not execute even though the application as a whole continues.
FileReader reads bytes.
Select one:
a. False
b. True
a. False
FileReader is used for reading streams of characters.
Final methods can be overridden.
Select one:
a. False
b. True
a. False
You use the final keyword in a method declaration to indicate that the method cannot be overridden by subclasses.
Garbage collection can be forced by Select one: a. Using the gc() method b. Extending the GarbageCollector class. c. None of the above d. It can never be forced.
d. It can never be forced.
JVM manages memory for you.
HashMaps can be used to allow null values and a null key.
Select one:
a. True
b. False
a. True
Hash table based implementation of the Map interface. This implementation provides all of the optional map operations, and permits null values and the null key. (The HashMap class is roughly equivalent to Hashtable, except that it is unsynchronized and permits nulls.)
How does a Collection differ from a Map?
Select one:
a. A Collection has an iterator whereas a Map does not.
b. Collection inherits from iterable, whereas Map does not.
c. Collections have a type whereas Maps have key-value pairs.
d. All of the Above.
d. All of the Above.
Map
An object that maps keys to values. A map cannot contain duplicate keys; each key can map to at most one value.
Collection
A collection represents a group of objects, known as its elements
If a try/catch block has multiple catches, the more general exception must come after the more specialized ones.
Select one:
a. True
b. False
a. True
a. True Interfaces have Select one: a. None of the above b. Implicit final methods c. Implicitly abstract methods d. Implemented methods
c. Implicitly abstract methods
A Java interface is a bit like a class, except a Java interface can only contain method signatures and fields. An Java interface cannot contain an implementation of the methods, only the signature (name, parameters and exceptions) of the method.