File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

IS CONCTRUCTOR IS A METHOD

 
Muhammad Usman
Greenhorn
Posts: 29
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello friends,
as we know constructor is a type of method but not having any return type even not void.
i like to know, if we define any variable in construction body, then is this variable will be a local variable or something else.

bye
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The variables in the constructor will be local to the constructor.
 
William Barnes
Ranch Hand
Posts: 986
Eclipse IDE Firefox Browser Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is the same as any other method. If you declare a variable in a method it is local to that method.
 
Karthikraj Magapu
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the constructor has a return type .. only this is not explicitly defined in the code .. the contructor return type is same as its class type. This return type is implicit. The contructor 'constructs' and returns an object of the class in which it is defined.
[ January 04, 2002: Message edited by: Karthikraj Magapu ]
 
Bosun Bello
Ranch Hand
Posts: 1510
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, the constructor's return type is implicit. it's actually an instance of the class i.e. the "this" refrence.
 
Rob Ross
Bartender
Posts: 2205
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not to be too nitpicky, but a constructor is NOT a method. It's a constructor. It's "special."
Back to your regular scheduled programming...
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, for now, since it gets loaded to the method area at class load time, I think that we can get away with calling it a "special type" of a method.
 
Michael Ernest
High Plains Drifter
Sheriff
Posts: 7292
Netbeans IDE VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a fun argument; people love to pick sides. For fun and to annoy purists, I like to go with the 'special type of method crowd.' But the 'not a method' crowd has some strong points to make, to wit: a constructor is a special type of method which has no return type, and can't be overridden regardless of its scope, is that right? And is java.lang.reflect.Constructor then a subclass of java.lang.reflect.Method, hm?
Now admit it, guys, there's no such thing as an "implied return type." Even if there was, it most certainly does equate to a class reference. You guys are making that one up.
Specially for Cindy: if I happen to load a brick in my refrigrator, does that make it a special type of food?
[ January 08, 2002: Message edited by: Michael Ernest ]
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Specially for Cindy: if I happen to load a brick in my refrigrator, does that make it a special type of food?

No - but it might suddenly make it a special type of "refrigerator thingy".
So we should call a constructor a special type of "method thingy"???
[ January 08, 2002: Message edited by: Cindy Glass ]
 
Rob Ross
Bartender
Posts: 2205
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm, I think "instance creation doohickey" has a nicer ring to it.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic