Constructor
Java supports a special type of method, called a constructor , that enables an object to initialise itself when it is created.Constructors have the same name as the class itself. Secondly , they do not specify a return type ,not even void.
Methods
A method is a collection of statements that perform some specific task and return the result to the caller. A method can perform some specific task without returning anything.
Some key Points between Constructor and Method is Shown below:-
Sr No. | Constructor | Methods |
1 | Constructor is used to initialize an object. | Method doesn't initialize an object./td> |
2 | It is invoked bt the system implicity. | It is invoked by the programmer. |
3 | It doesn't have return type. | It has return type. |
4 | Constructor name must be same as class name. | Methods name can be anything. |
5 | Construcor cannot be inherited by subclass. | Method can be inherited by subclass. |
6 | Constructor is call when object is created. | To call method, new operator is used. |
2 Comments
Ty bro for this ����
ReplyDeletewc
ReplyDelete