Friday, 27 April 2012

JAVA interview questions 17

Q161. What is the difference between a field variable and alocal variable? 
A field variable is a variable that is declared as a member of a class. A local variable is a variable that is declared local to a method. 

Q162. Under what conditions is an object's finalize()method invoked by the garbage collector? 
The garbage collector invokes an object's finalize() method when it detects that the object has become unreachable. 

Q163. How are this() and super() used with constructors? 
this() is used to invoke a constructor of the same class. super() is used to invoke a superclass constructor. 

Q164. What is the relationship between a method's throwsclause and the exceptions that can be thrown during themethod's execution? 
A method's throws clause must declare any checked exceptions that are not caught within the body of the method. 

Q165. What is the difference between the JDK 1.02 eventmodel and the event-delegation model introduced withJDK 1.1? 
The JDK 1.02 event model uses an event inheritance or bubbling approach. In this model, 
components are required to handle their own events. If they do not handle a particular event, the 
event is inherited by (or bubbled up to) the component's container. The container then either 
handles the event or it is bubbled up to its container and so on, until the highest-level container has been tried..In the event-delegation model, specific objects are designated as event handlers for GUI components. These objects implement event-listener interfaces. The event-delegation model is more efficient than the event-inheritance model because it eliminates the processing required to support the bubbling of unhandled events. 

Q166. How is it possible for two String objects withidentical values not to be equal under the == operator? 
The == operator compares two objects to determine if they are the same object in memory. It is 
possible for two String objects to have the same value, but located indifferent areas of memory. 

Q167. Why are the methods of the Math class static? 
So they can be invoked as if they are a mathematical code library. 

Q168. What Checkbox method allows you to tell if aCheckbox is checked? 
Q169. What state is a thread in when it is executing? 
An executing thread is in the running state. 

Q170. What are the legal operands of the instanceofoperator? 
The left operand is an object reference or null value and the right operand is a class, interface, or array type. 

No comments:

Post a Comment