aspose file tools*
The moose likes Associate Certification (OCAJP 7/8) and the fly likes Enthuware Mocks question. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Associate Certification (OCAJP 7/8)
Bookmark "Enthuware Mocks question." Watch "Enthuware Mocks question." New topic
Author

Enthuware Mocks question.

Kancharla Madhu
Ranch Hand

Joined: May 06, 2012
Posts: 109



What changes, when made independently, will enable the code to compile and run?

Correct Answer : Replace Logger logger = new Logger(); with: util.log4j.Logger logger = new util.log4j.Logger();

Looks like it is wrong as Logger.java was defined in different package with default scope. So,the statement will not compile.







Champions arenĀ“t made in the gyms. Champions are made from something they have deep inside them - a DESIRE, a DREAM, a VISION
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2517
    
    8

Well the "new Logger()" is ambiguous. There is no Logger class in java.lang package since the code has no import statements. The Java API has however a java.util.logging.Logger but the constructor is protected.

Therefore, you need to explicitly use the fully qualified name for Logger.


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5 OCPBCD5
Kancharla Madhu
Ranch Hand

Joined: May 06, 2012
Posts: 109

If we define Logger.java as public then code will compile without any problem.
Paul Anilprem
Enthuware Software Support
Ranch Hand

Joined: Sep 23, 2000
Posts: 3313
    
    7
You have not quoted the code exactly as given in the question. The Logger class is defined as public but you've omitted public.
-Paul.


Enthuware - Best Mock Exams and Questions for Oracle/Sun Java Certifications
Quality Guaranteed - Pass or Full Refund!
Kancharla Madhu
Ranch Hand

Joined: May 06, 2012
Posts: 109

public modifier was not there in the actual question itself,If you want me send the snapshot of the question I can.
Paul Anilprem
Enthuware Software Support
Ranch Hand

Joined: Sep 23, 2000
Posts: 3313
    
    7
Kancharla Madhu wrote:public modifier was not there in the actual question itself,If you want me send the snapshot of the question I can.

I see that this question ( QID: enthuware.ocajp.i.v7.2.915 ) was last updated on 09/11/2012 and it does have the modifier (at least since then). So you seem to be using an older version of the question bank. Please update your question bank.

HTH,
Paul.
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2517
    
    8

Kancharla Madhu wrote:If we define Logger.java as public then code will compile without any problem.


Well even if the class is declared public, the Logger class is in different package from the TestClass. So it remains ambiguous.

A class can access other classes in the same package only. Any sub-packages will need imports.
Paul Anilprem
Enthuware Software Support
Ranch Hand

Joined: Sep 23, 2000
Posts: 3313
    
    7
K. Tsang wrote:
Kancharla Madhu wrote:If we define Logger.java as public then code will compile without any problem.


Well even if the class is declared public, the Logger class is in different package from the TestClass. So it remains ambiguous.

A class can access other classes in the same package only. Any sub-packages will need imports.


No import is required if you use the fully qualified class name as is used in the correct option.

HTH,
Paul.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Enthuware Mocks question.