File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Constructor

 
putti don
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 580
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1599
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vidyasagar you mean... a constructor can call another constructor only using "this"??? And if it doesnt then it actually means a call to method???
 
vidya sagar
Ranch Hand
Posts: 580
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 1599
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A constructor can call another constructor only using "this".


Thanks VS!
 
Mandy Hou
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A constructor can call another constructor only using "this".
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic