Advertisements
Advertisements
Questions
State the difference between constructor and method.
Give differences between a constructor and a method.
Distinguish Between
Advertisements
Solution
| S. No. | Constructor | Function/Method |
| 1. | The constructor is named the same as the class name. | A function's name differs from its class name. |
| 2. | Constructors do not return any value, including void. | Functions may or may not return a value. |
| 3. | Constructors are often public. | A method can be public or private. |
| 4. | The constructor is simply used to set data members. | A method is utilized to execute mathematical or logical tasks. |
shaalaa.com
Is there an error in this question or solution?
