KnowledgeBoat Logo
|

Computer Applications

What is a constructor? Why do you need a constructor?

Java Constructors

10 Likes

Answer

A constructor is a member method of a class that is used to initialise the instance variables. It has the same name as that of its defining class and does not have a return type.

A constructor is needed as it instructs the computer to perform the start-up tasks of a new object. These can be like assigning default values to instance variables, aligning all the buttons on a screen when a new window object is created, or moving the cursor to a specific data entry field for the user input.

Answered By

5 Likes


Related Questions