Advertisements
Advertisements
Question
A constructor ______ (can/cannot) be called as other functions.
Fill in the Blanks
Advertisements
Solution
A constructor cannot be called as other functions.
Explanation:
- Regular methods can be called explicitly at any time using an object name (e.g., object.methodName()).
- A constructor, however, can only be invoked once when an object is being born, using the new keyword. You cannot call a constructor later in the program to run its code again.
shaalaa.com
Is there an error in this question or solution?
Chapter 4: Constructors - Exercises [Page 115]
