1.

(a) Define Constructors . Also write two charactertics of a constructor. (b) What is a wrapper class? Explain with the help of a suitable example.

Answer»

(a) A constructor is a special method. It is used to initialize the data members of the class.

two charactertics are:

(i) The constructor has the same name as the class, has no return type, and may or may not have a parameter list. 

(ii) Whenever a new object of a class is created, the constructor of the class is invoked automatically.

(b) A Wrapper class is a class whose object wraps or contains a primitive data types. When we create an object to a wrapper class, it contains a field and in this field, we can store a primitive data types.

They convert primitive data types into objects. Objects are needed if we wish to modify the arguments passed into a method (because primitive types are passed by value Each of the eight primitive types has a wrapper class defined.

For example: Integer wrapper class converts a string into its integer value.



Discussion

No Comment Found

Related InterviewSolutions