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

Have a question about constructor

 
chang nanny
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
"super()" can put in line 4,right?
public class Animal{ //1
String name; //2
Animal(String name){ //3
//4
this.name=name; //5
}

Animal(){
this(makeRandomName());
}

static String makeRandomName(){
return name;
}
}
Thank you.
 
Lionel Orellana
Ranch Hand
Posts: 87
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all your code won't compile because the variable name is not static and you're trying to use it in the static method makeRandomName
If you make name static, then yes, you can type super(); in line 4 and it'll work. But even if you don't include the call to super(); the compiler will do it for you. So in this case it makes no difference whatsoever.
The best is to go ahead and see these things in action yourself. Just compile your code, make changes, compile again ...
cheers
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic