Can you explain why a constructor doesn't have return type?The primary goal of a constructor is to create an object. Though the constructor resembles a method, its explicit purpose is to initialize the instance variables. Assignment operation resembles like a method, it is to be done just before an object is created. It is certain that the constructor can create the object of that class only. This agreement is unambiguous and crystal clear. Hence a constructor does not have return type.
|