Subscribe Us

Core Java - Interview Questions and Answers

151. Can a for statement loop indefinitely?

Ans : Yes.

152. What is the difference between while statement and a do statement?

Ans : A while statement checks at the beginning of a loop to see whether the next loop iteration should occur.
A do statement checks at the end of a loop to see whether the next iteration of a loop should occur. The do statement will always execute the body of a loop at least once.


Introduction to Classes and Methods

153. Which is used to get the value of the instance variables?

Ans: Dot notation.

154. The new operator creates a single instance named class and returns a
reference to that object.

a)True
b)False
Ans: a.

155. A class is a template for multiple objects with similar features.

a)True
b)False
Ans: a.

156. What is mean by garbage collection?

Ans: When an object is no longer referred to by any variable, Java automatically
reclaims memory used by that object. This is known as garbage collection.

157. What are methods and how are they defined?

Ans: Methods are functions that operate on instances of classes in which they are defined.Objects can communicate with each other using methods and can call methods in other classes.
Method definition has four parts. They are name of the method, type of object or primitive type the method returns, a list of parameters and the body of the method.
A method's signature is a combination of the first three parts mentioned above.

158. What is calling method?

Ans: Calling methods are similar to calling or referring to an instance variable. These methods are accessed using dot notation.
Ex: obj.methodname(param1,param2)

159. Which method is used to determine the class of an object?

Ans: getClass( ) method can be used to find out what class the belongs to. This class is defined in the object class and is available to all objects.

160. All the classes in java.lang package are automatically imported when
a program is compiled.

a)True
b)False
Ans: a.


Post a Comment

0 Comments