This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question 7 of Online materials for Certified Associate Java SE 8 Programmer I: errata or trick?

 
Vitaliy Ovcharenko
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a question 7 from Exam 1 of Online materials for Certified Associate Java SE 8 Programmer I (Boyarsky and Selikoff):

What is the output when new BlackRhino is called?



Possible choices are: A. 123; B. 132; C. 12; D. 13; E. This code does not compile.

The first point which is not clear: are the both classes in the same file or not? If they are the code obviously could not be compiled because both of them are public. From another hand none of them has a main() method which is the reason to be not compiled as well. So the right answer should be E. But this is not correct from the authors' point of view. They say that the right answer is A. What am I missing?
 
Vitaliy Ovcharenko
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, it seems like the authors implie that the class BlackRhino is used somewhere else. For example:

In this case it works ok. But it not obvious from the question.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to CodeRanch!

Yes, the main method was implied. It's also the case that when you see two public classes, you should assume they are in different files. In fact, Oracle added that explicitly to the objectives this year!
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vitaliy Ovcharenko,

First of all, a warm welcome to CodeRanch!

Vitaliy Ovcharenko wrote:The first point which is not clear: are the both classes in the same file or not? If they are the code obviously could not be compiled because both of them are public.

One of the official assumptions you should consider when taking the exam (and which can be found on the official OCAJP8 certification page) states the following: No file or directory path names for classes: If a question does not state the file names or directory locations of classes, then assume one of the following, whichever will enable the code to compile and run: (a) All classes are in one file or (b) Each class is contained in a separate file, and all files are in one directory.

Vitaliy Ovcharenko wrote:From another hand none of them has a main() method which is the reason to be not compiled as well.

That's completely incorrect! Which statement made you conclude that a class is required to have a main() method in order to successfully compile? Because that's plain wrong! This class will compile successfullyIf you want to execute a class (using the java command), the class is required to have a main() method with the appropriate method declaration (public static void main(String[] args)). But that's definitely not a requirement to successfully compile the class.

Hope it helps!
Kind regards,
Roel
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic