constructor or method
I cannot figure out how the constructor differs from the method in Java. For me personally, the only difference is using the special word "this" in constructor. I would like to distinguish between their functions and structure. Help me understand, please.

Satya KarkiPosted Apr 7, 2021, 12:45 PM
Rijwan AnsariPosted Apr 7, 2021, 12:30 PM
Sachin SinghPosted Apr 7, 2021, 8:07 AM
Salman BegPosted Apr 6, 2021, 4:57 PM
Aman GuptaPosted Apr 6, 2021, 4:40 PM
The definitions of constructors and methods look similar in code. They can take parameters, they can have modifiers (e.g.
public), and they have method bodies in braces.newoperator, while methods perform operations on objects that already exist.Constructors can't be called directly; they are called implicitly when the
newkeyword creates an object. Methods can be called directly on an object that has already been created withnew.Constructors must be named with the same name as the class name. They can't return anything, even
void(the object itself is the implicit return).