This content originally appeared on DEV Community and was authored by Keshav Kumar
When you study first time about constructor it almost feels like this is completely equal to Method but no its not. You might be thinking what is the need to use constructor, we use constructor to initialize some value. when we use ??????? ??? ?;
in the class the defalut value of a is 0. But lets say if we want the default value of '?' should be 5 then we can achieve that thorugh costructors.
now you might be thinking how will we identify which one is Method and which one is constructor, for that you have to see the name of constructor or method if that is equal to the name of class then it is a constructor else its a method.
also constructor is used to give default value and method is used to do some kind of operations like add();
This content originally appeared on DEV Community and was authored by Keshav Kumar
Keshav Kumar | Sciencx (2021-05-17T02:58:43+00:00) Difference Between Methods and Constructors (Java).. Retrieved from https://www.scien.cx/2021/05/17/difference-between-methods-and-constructors-java/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.