Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

What is the difference constructor and method?

user-image
Question ajoutée par Ramakrishna Ilavarapu
Date de publication: 2014/04/15
Maria Thomas
par Maria Thomas , Tech Lead , J P Morgan Chase

Constructor is the point of initialisation of any object. If an explicit constructor is not given, the class has a default no arguments constructor that is internal to it which would be called when the object is created using the new operator. Constructor does not have a return type.

In contrast a method is created by the user to do some actions on the object. It is explicitly invoked on the object. It has a return type.

shabbir hussain
par shabbir hussain , Billing Analyst Consultant , Ebone Network (Private) Limited

The important difference between constructors and methods is that constructors create and initialize objects that don't exist yet, while methods perform operations on objects that already exist.

More Questions Like This