• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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: 4810
52
  • 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 public.
-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: 4810
52
  • 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 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
Posts: 4810
52
  • 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 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.
 
What do you have in that there bucket? It wouldn't be a tiny ad by any chance ...
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic