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
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?