This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what happens with this code?

 
Andres Gonzalez
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Kaz Yosh
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess those methods are static so object looks for the method with same type as it does for variables.
 
Andres Gonzalez
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry, didn't get that one... could you explain it a bit more in depth...
 
Anupam Sinha
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks... Yes, I was right, I emailed javacertificate.com and they updated the question. Now they are in different Java files.
 
Lei Zheng
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic