0

difference between constructor and function?and also one similarity

28th Aug 2016, 1:59 AM
Rohan agarwal
Rohan agarwal - avatar
2 ответов
+ 2
constructor used during creation of java objects. where as methods will be called with reference of object variable. constructor has no return type mentioned including void where as method will have return type mentioned. Similarity, method and constructor can accept parameters.
28th Aug 2016, 3:32 AM
Mahender
Mahender - avatar
0
methods are written by the programmers. even constructors are. But there are default constructors too. So even if you don't define a constructor, there is always a default constructor that is being called, whenever an object is created. Whereas, method has to be defined by the programmers, and must be called by the programmer only cz there is no default calling of methods. one big difference is: Constructors have the name of the class in which they're being defined. We can't have a method name same as the class name. Also Constructors don't have any return type, whereas methods must have one.
19th Sep 2016, 2:06 PM
Tanya
Tanya - avatar