Computer Science, asked by monicaanand8610, 1 year ago

Write the differences between methods and constructors.

Answers

Answered by Prateek001
0
The important difference between constructors and methods are:

1. Constructors create and initialize objects that don't exist yet, while methods perform operations on objects that already exist.

2. Constructors can't be called directly; they are called implicitly when the new keyword creates an object. Methods can be called directly on an object that has already been created with new.

3. The definitions of constructors and methods look similar in code.

4. Constructors must be named with the same name as the class name. 

5. Methods must be declared to return something, although it can be void.

Hope it helps, thanks
if you like my answer then mark it as brainliest
Answered by gratefuljarette
2

The difference between methods and constructors:

Methods:

  • It consists of java program to be executed.  
  • Methods can return some values sometimes.
  • Methods are invoked only by the developer. We need to always explicitly declare or define the methods.
  • We can give any names to the methods.

Constructors:

  • It is used to initialize an object.  
  • Constructors can never return any value.
  • Constructors are invoked sometimes by default.  
  • The constructor name should be always the same as the name of the class.

Learn more about Methods and constructors

Diffrence between a constructor and method in java programming

https://brainly.in/question/8653605

Difference b/w method overloading and constructor overloading

https://brainly.in/question/5362151

Similar questions