Advertisements
Advertisements
प्रश्न
State the difference between constructor and method.
Give differences between a constructor and a method.
अंतर स्पष्ट करें
उत्तर
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
क्या इस प्रश्न या उत्तर में कोई त्रुटि है?