0
what is the difference between method and a constructor
4 Antworten
+ 2
Constructor is a method which is called when a new instance of the class is created.
+ 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.
+ 1
Construtor is a method which has the name as its class name and has no explicit return type.
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