You need to sign in to do that
Don't have an account?

Constructor vs method
Hi guys,
Can anyone tell me when a constructor is used and preferred more than a method.
What are the limitations of both method and constructor
Thanks,
Abhilash
Can anyone tell me when a constructor is used and preferred more than a method.
What are the limitations of both method and constructor
Thanks,
Abhilash
main difference:-
1.Constructor are used to initialize the state of object,where as method is expose the behaviour of object.
2.Constructor must not have return type where as method must have return type.
3.Constructor name same as the class name where as method may or may not the same class name.
4.Constructor invoke implicitly where as method invoke explicitly.
5.Constructor compiler provide default constructor where as method compiler does't provide.
Example:-
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh