Friday, May 9, 2008

Java Interview Questions 40

196. What is an Object and how do you allocate memory to it?
Ans. Object is an instance of a class and it is a software unit that combines a
structured set of data with a set of operations for inspecting and manipulating
that data. When an object is created using new operator, memory is allocated to it.

197. What is the difference between constructor and method?
Ans. Constructor will be automatically invoked when an object is created whereas
method has to be called explicitly.

198. 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.

199. What is the use of bin and lib in JDK?
Ans. Bin contains all tools such as javac, appletviewer, awt tool, etc., whereas
lib contains API and all packages.

200. What is casting?
Ans. Casting is used to convert the value of one type to another.

No comments:

Useful Information