Differences between Constructors and method
Differences between Constructors and method
Constructors | Methods |
---|---|
A Constructor is a block of code that initializes a newly created object. | A Method is a collection of statements which returns a value upon its execution. |
A Constructor can be used to initialize an object. | A Method consists of Java code to be executed. |
A Constructor is invoked implicitly by the system. | A Method is invoked by the programmer. |
A Constructor is invoked when a object is created using the keyword new. | A Method is invoked through method calls. |
A Constructor doesn’t have a return type. | A Method must have a return type. |
A Constructor initializes a object that doesn’t exist. | A Method does operations on an already created object. |
A Constructor’s name must be same as the name of the class. | A Method’s name can be anything. |
A class can have many Constructors but must not have the same parameters. | A class can have many methods but must not have the same parameters. |
A Constructor cannot be inherited by subclasses. | A Method can be inherited by subclasses. |
Comments
Post a Comment