Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (6.5k points)
Please tell me the differences between constructors and methods?

1 Answer

0 votes
by (11.3k points)

Although constructors and methods operate in a very similar way, some differences do exist between them in terms of implementation, syntax, and theory:

  • A constructor is used to initialize an instance of a class while a method is used to express the behaviour of that class' instance. 
  • A constructor DOES NOT have a return type while a return type must be specified for a method.
  • Even if we don't define a constructor explicitly, a default constructor is still executed. But if we don't explicitly call for a method, that method will not be executed. 
  • A constructor has to be the same name as the class while a method may or may not have the same name as that of the class. 

Learn Java to excel in it.

Related questions

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

Browse Categories

...