wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes what happens with this code? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "what happens with this code?" Watch "what happens with this code?" New topic
Author

what happens with this code?

Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
taken from javacertificate.com

according to them, the answer is:
Compilation succeeds, the output is BaseClass: doCommand.
but I have one question. There are 2 public classes in this code (the code line is starting from 1 - 14, so I assume is a single java file). I'd say code would not even compile because only one class can be public. Am I missing something?


I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
Kaz Yosh
Ranch Hand

Joined: May 22, 2003
Posts: 63
I guess those methods are static so object looks for the method with same type as it does for variables.


"If anything can go wrong, it will"
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
sorry, didn't get that one... could you explain it a bit more in depth...
Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1088
Hi Andres
Yes you are right Andres. Well if the code didn't specified that the two classes are in seperate files then this should be considered wrong. Secondly the code in your question starts from 1 that means the code is the complete code and doesn't has any enclosing class or whatever so moreever the question's answer in its present form should be the code doesn't compile.
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
Thanks... Yes, I was right, I emailed javacertificate.com and they updated the question. Now they are in different Java files.
Lei Zheng
Greenhorn

Joined: May 28, 2003
Posts: 3
I have read some books.I remember that one of those books says that you can not have two public class in a file if you use the SUN'JDK to compile the codes,but when you use other tools for example JBuilder ,that situation is acceptable.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what happens with this code?