what is the difference between method and a constructor | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

what is the difference between method and a constructor

24th Jul 2016, 8:52 AM
ajit
ajit - avatar
4 Answers
+ 2
Constructor is a method which is called when a new instance of the class is created.
24th Jul 2016, 10:33 AM
Marcin
+ 1
A constructor is a special method, its implicitly called when a class is initialized but you can override the default constructor by creating your own that initializes your variables or objects, and it must be called the same name as your class's name.
25th Jul 2016, 12:52 AM
Eric Gitangu
Eric Gitangu - avatar
+ 1
Construtor is a method which has the name as its class name and has no explicit return type.
25th Jul 2016, 4:03 PM
Dhana sri sowmya avidi
Dhana sri sowmya avidi - avatar
0
constructor must have same name as class name constructor has no return type constructor can be default or user defined default constructor is invoked automatically when class is initialized
5th Aug 2016, 7:10 AM
sachin tomar
sachin tomar - avatar