java constructor
4 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   rajesh_kp
Posted On:   Tuesday, June 1, 2004 07:13 AM

why was the java constructor designed not to have a return type?

Re: java constructor

Posted By:   Venkat_Hariharan  
Posted On:   Wednesday, June 2, 2004 10:59 PM

This is because the return type of the constructor is same as that of the class.

Re: java constructor

Posted By:   David_Thornton  
Posted On:   Tuesday, June 1, 2004 10:23 PM

The constructor does not have a return type because only methods have return types (or void). A constructor creates a new object that is an instance of its class (type) so you could argue that it has an implied "return type" which is the type for which it is defined.



public class MyClass {

public static void main(String[] args) {
Object myObject = new MyClass();
System.out.println(myObject.getClass());
}
}

Re: java constructor

Posted By:   Brian_Glodde  
Posted On:   Tuesday, June 1, 2004 08:34 PM

Re: java constructor

Posted By:   tech_tech  
Posted On:   Tuesday, June 1, 2004 04:58 PM

looks like there is some test/ homework going on somewhere - everyone is asking same question.
About | Sitemap | Contact