-
When can an object reference be cast to an interface reference
An object reference be cast to an interface reference when the object implements thereferenced interface.
-
What is the difference between a static and a non-static inner class
A non-static inner class may have object instances that are associated with instances ofthe class's outerclass. A static inner class does not have any object instances.
-
How are commas used in the initialization and iteration parts of a for statement
Commas are used to separate multiple statements within the initialization and iterationparts of a forstatement.
-
What class allows you to read objects directly from a stream?
The ObjectInputStream class supports the reading of objects from input streams.
-
What methods are used to get and set the text label displayed by a Buttonobject
getLabel() and setLabel()
-
What is the difference between the Font and FontMetrics classes
The FontMetrics class is used to define implementation-specific properties, such asascent and descent, of aFont object.
-
What is the purpose of the finally clause of a try-catch-finally statement
The finally clause is used to provide the capability to execute code no matter whether ornot an exception isthrown or caught.
-
What is the purpose of finalization
The purpose of finalization is to give an unreachable object the opportunity to performany cleanupprocessing before the object is garbage collected.
-
What classes of exceptions may be thrown by a throw statement
A throw statement may throw any expression that may be assigned to the Throwabletype.
-
What must a class do to implement an interface
It must provide all of the methods in the interface and identify the interface in itsimplements clause.
-
What are the legal operands of the instanceof operator
The left operand is an object reference or null value and the right operand is a class,interface, or array type.
-
What modifiers can be used with a local inner class
A local inner class may be final or abstract.
-
What modifiers may be used with an interface declaration
An interface may be declared as public or abstract.
-
For which statements does it make sense to use a label
The only statements for which it makes sense to use a label are those statements that canenclose a break orcontinue statement.
-
How are the elements of a CardLayout organized
The elements of a CardLayout are stacked, one on top of the other, like a deck of cards.
-
What classes of exceptions may be caught by a catch clause
A catch clause can catch any exception that may be assigned to the Throwable type. Thisincludes the Errorand Exception types.
-
What class of exceptions are generated by the Java run-time system
The Java runtime system generates RuntimeException and Error exceptions.
-
-
How are this and super used
This is used to refer to the current object instance. super is used to refer to the variablesand methods of the superclass of the current object instance.
-
What happens if an exception is not caught
An uncaught exception results in the uncaughtException() method of the thread'sThreadGroup being invoked, which eventually results in the termination of the programin which it is thrown.
Java Interview Questions
Ans