Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (7k points)
I am new to Java and I exactly do not the difference between methods and constructors and what makes them unique. Can someone help me define them and differentiate between the two?

1 Answer

0 votes
by (13.1k points)

The methods are something we can call explicitly whereas, a constructor is called implicity when we initialize an object using a new operator. A constructor’s name has to be the name of a class whereas, for a method, there is no need.

A constructor does not have a return type whereas, a method must have a return type unless it is a void type.

A method can be implemented any number of times, but the constructor is implemented only once per object. The constructors are chained and they must be called in a particular order whereas, for a method, there is no such thing. A constructor is provided by default by the compiler but the compiler does not provide a default method.

Check this java tutorial to know more about Java.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Mar 3, 2021 in Java by Jake (7k points)

Browse Categories

...