File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Have a question about constructor

chang nanny

Joined: Feb 15, 2004
Posts: 14
"super()" can put in line 4,right?
public class Animal{ //1
String name; //2
Animal(String name){ //3
//4; //5


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 ...
I agree. Here's the link:
subject: Have a question about constructor
It's not a secret anymore!