• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Enthuware Mocks question.

 
Ranch Hand
Posts: 109
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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.






 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Kancharla Madhu
Ranch Hand
Posts: 109
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If we define Logger.java as public then code will compile without any problem.
 
Enthuware Software Support
Posts: 4907
60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have not quoted the code exactly as given in the question. The Logger class is defined as public but you've omitted coderanch.
-Paul.
 
Kancharla Madhu
Ranch Hand
Posts: 109
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4907
60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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



Well even if the class is declared coderanch, 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
Posts: 4907
60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 coderanch, 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic