Thursday 26 April 2012

JAVA interview questions 15

Q141. What is the difference between static and non-staticvariables? 
A static variable is associated with the class as a whole rather than with specific instances of a class. Non-static variables take on unique values with each object instance. 

Q142. What is the difference between the paint() and repaint() methods? 
The paint() method supports painting via a Graphics object. The repaint() method is used to cause paint() to be invoked by the AWT painting thread.

Q143. What is the purpose of the File class? 
The File class is used to create objects that provide access to the files and directories of a local file system. 

Q144. Can an exception be rethrown? 
Yes, an exception can be rethrown. 

Q145. Which Math method is used to calculate the absolute value of a number? 
The abs() method is used to calculate absolute values. 

Q146. How does multithreading take place on a computer with a single CPU? 
The operating system's task scheduler allocates execution time to multiple tasks. By quickly 
switching between executing tasks, it creates the impression that tasks execute sequentially. 

Q147. When does the compiler supply a default constructor for a class? 
The compiler supplies a default constructor for a class if no other constructors are provided. 

Q148. When is the finally clause of a try-catch-finally statement executed? 
The finally clause of the try-catch-finally statement is always executed unless the thread of 
execution terminates or an exception occurs within the execution of the finally clause. 

Q149. Which class is the immediate superclass of the Container class? 
Component 

Q150. If a method is declared as protected, where may themethod be accessed? 
A protected method may only be accessed by classes or interfaces of the same package or by subclasses of the class in which it is declared. 

No comments:

Post a Comment