• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Enthuware Mocks question.

 
Kancharla Madhu
Ranch Hand
Posts: 109
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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.






 
K. Tsang
Bartender
Posts: 3457
14
Android Java
  • Mark post as helpful
  • send pies
  • 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 Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If we define Logger.java as public then code will compile without any problem.
 
Paul Anilprem
Enthuware Software Support
Ranch Hand
Posts: 3753
10
  • Mark post as helpful
  • send pies
  • 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 Java Spring
  • Mark post as helpful
  • send pies
  • 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
Ranch Hand
Posts: 3753
10
  • Mark post as helpful
  • send pies
  • 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: 3457
14
Android Java
  • Mark post as helpful
  • send pies
  • 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
Ranch Hand
Posts: 3753
10
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic