| Author |
Constructor
|
putti don
Greenhorn
Joined: Jul 28, 2005
Posts: 20
|
|
Hi, public class Test19 { float f; Test19(float f){ System.out.println(f); } Test19(){ Test19(1); f = 3; } public static void main(String args[]) { Test19 t = new Test19(); } } why i am getting compile time error for this?can anyone please explain. Thanks.
|
 |
vidya sagar
Ranch Hand
Joined: Mar 02, 2005
Posts: 580
|
|
hi
Test19(){ Test19(1); //1 f = 3; }
Test19(1) statement looks for method name Test19 which takes argument of int.But actually we didnot have method in this name. Suppose if we want to call constructor, then we should specify the constructor using this.(here it will -- this(1)) Hope u get it
|
 |
Akhilesh Trivedi
Ranch Hand
Joined: Jun 22, 2005
Posts: 1493
|
|
|
Vidyasagar you mean... a constructor can call another constructor only using "this"??? And if it doesnt then it actually means a call to method???
|
Keep Smiling Always — My life is smoother when running silent. -paul
[FAQs] [Certification Guides] [The Linux Documentation Project]
|
 |
vidya sagar
Ranch Hand
Joined: Mar 02, 2005
Posts: 580
|
|
Vidyasagar you mean... a constructor can call another constructor only using "this"??? And if it doesnt then it actually means a call to method???
Yes
|
 |
Akhilesh Trivedi
Ranch Hand
Joined: Jun 22, 2005
Posts: 1493
|
|
A constructor can call another constructor only using "this".
Thanks VS!
|
 |
Mandy Hou
Greenhorn
Joined: Oct 15, 2005
Posts: 21
|
|
|
A constructor can call another constructor only using "this".
|
Regards<br />Mandy<br /> <br />-----------------<br />Thinking,Thinking,Thinking,<br />Before you do any action!!!
|
 |
 |
|
|
subject: Constructor
|
|
|