| Author |
constructor problem
|
ssasi kumar
Greenhorn
Joined: Feb 23, 2011
Posts: 24
|
|
hi,
how to call constuctor from same class method. i am using "this" its generates error then which via constructor call from method in same class...
thanks for all,
sasikumar
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14685
|
|
|
Constructors are not methods and are only invoked during the construction of an object. Why do you want to call one ?
|
[My Blog]
All roads lead to JavaRanch
|
 |
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
|
|
ssasi kumar wrote:
then which via constructor call from method in same class...
the only way to call the constructor from method is by using *new* key word.
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14685
|
|
Seetharaman Venkatasamy wrote:the only way to call the constructor from method is by using *new* key word.
Actually there are other ways, like via Reflection (Class.newInstance())
|
 |
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
|
|
Christophe Verré wrote:Actually there are other ways, like via Reflection (Class.newInstance())
Yes . thanks
|
 |
ssasi kumar
Greenhorn
Joined: Feb 23, 2011
Posts: 24
|
|
hi,
here i attach my snippet code. there is one error occur, that method called fallen in infinite loop. how to avoid infinite loop..
please reply me.....
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12953
|
|
So, does this have something to do with your first post or is this a completely different question? If it is a completely new question, then next time please just post it in a new topic instead of appending it to an existing topic as a reply.
Please UseCodeTags when you post source code - I've added them for you in your post above.
The code you posted does not seem to have an infinite loop. You could get an infinite recursive loop if you'd have one method that calls another, that again calls the one, that again calls the other, ... but I don't see that in the two methods you posted.
Also, the code you posted doesn't even compile. Lines 4 and 5 both contain a return statement. The compiler will complain about unreachable code in line 5 when you try to compile this. Please PostRealCode so that we can really see what's happening and what the problem might be.
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
 |
|
|
subject: constructor problem
|
|
|