wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Have a question about constructor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Have a question about constructor" Watch "Have a question about constructor" New topic
Author

Have a question about constructor

chang nanny
Greenhorn

Joined: Feb 15, 2004
Posts: 14
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

Joined: Mar 19, 2004
Posts: 87
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
 
subject: Have a question about constructor