Difference Between Methods and Constructors (Java).

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 th…


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


Print Share Comment Cite Upload Translate Updates
APA

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/

MLA
" » Difference Between Methods and Constructors (Java).." Keshav Kumar | Sciencx - Monday May 17, 2021, https://www.scien.cx/2021/05/17/difference-between-methods-and-constructors-java/
HARVARD
Keshav Kumar | Sciencx Monday May 17, 2021 » Difference Between Methods and Constructors (Java).., viewed ,<https://www.scien.cx/2021/05/17/difference-between-methods-and-constructors-java/>
VANCOUVER
Keshav Kumar | Sciencx - » Difference Between Methods and Constructors (Java).. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/05/17/difference-between-methods-and-constructors-java/
CHICAGO
" » Difference Between Methods and Constructors (Java).." Keshav Kumar | Sciencx - Accessed . https://www.scien.cx/2021/05/17/difference-between-methods-and-constructors-java/
IEEE
" » Difference Between Methods and Constructors (Java).." Keshav Kumar | Sciencx [Online]. Available: https://www.scien.cx/2021/05/17/difference-between-methods-and-constructors-java/. [Accessed: ]
rf:citation
» Difference Between Methods and Constructors (Java). | Keshav Kumar | Sciencx | 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.

You must be logged in to translate posts. Please log in or register.