File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes IS CONCTRUCTOR IS A METHOD Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "IS CONCTRUCTOR IS A METHOD" Watch "IS CONCTRUCTOR IS A METHOD" New topic
Author

IS CONCTRUCTOR IS A METHOD

Muhammad Usman
Greenhorn

Joined: Nov 18, 2001
Posts: 29
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


an student of Operation Badar ( a educational movement in Pakistan).
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
The variables in the constructor will be local to the constructor.


"JavaRanch, where the deer and the Certified play" - David O'Meara
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 984

That is the same as any other method. If you declare a variable in a method it is local to that method.


Please ignore post, I have no idea what I am talking about.
Karthikraj Magapu
Greenhorn

Joined: Dec 04, 2001
Posts: 9
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 ]

SJCP<br />SCEA P1
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
Yes, the constructor's return type is implicit. it's actually an instance of the class i.e. the "this" refrence.


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Rob Ross
Bartender

Joined: Jan 07, 2002
Posts: 2205
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...


Rob
SCJP 1.4
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
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

Joined: Oct 25, 2000
Posts: 7292

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 ]

Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
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

Joined: Jan 07, 2002
Posts: 2205
Hmm, I think "instance creation doohickey" has a nicer ring to it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: IS CONCTRUCTOR IS A METHOD
 
Similar Threads
the 4 types of the access modifiers
Why do we "int arr[]= new int[4];
how to find type of a primitive variable?
a question about static
Object of an object