+ 1
Please what's the main idea behind constructors???
for instance when someone is using a constructor, what's the programmer trying to do?
4 Answers
+ 1
Constructors are usually used to initialize instance variables
+ 1
Constructors are specific to object-oriented programming languages. Programs written in these languages consist of classes, which define sets of properties (data) and behaviours (methods). These are called the classâs members.
An instance of a class is an object created from its class definition. It obtains a copy of the defined members (Iâm leaving out some stuff here for simplicity) and occupies physical space in memory. The process of creating an object this way is called instantiation.
Constructors are methods found (in one way or another) in every class. In order for instantiation to occur, one of the classâs constructors must be invoked to construct the object instance and initialize its data members to known values.
After this is completed, the object can be used by accessing its exposed data and invoking its methods as needed. But a constructor can only be used once in an objectâs lifetime: to create that particular instance of its class.
0
You use it when you want to initialize an object
0
Constructor is used to create objects
It is called sutomatically while creating object
Since constructor is non static we can call both static and non static methods
We can perform overloading and can call superclass constructor very easily using super()
We can perform chaining of cobstructors using this()