aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Plz help me in solving the problem of JAVAC comand 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 » Programmer Certification (SCJP/OCPJP)
Reply locked New topic
Author

Plz help me in solving the problem of JAVAC comand

varunmehta kumar
Greenhorn

Joined: Jun 13, 2006
Posts: 12
Given the default classpath:
/foo
And this directory structure:
foo
|
test
|
xcom
|--A.class
|--B.java
And these two files:
package xcom;
public class A { }
package xcom;
public class B extends A { }


Which allows B.java to compile? (Choose all that apply.)
A. Set the current directory to xcom then invoke
javac B.java
B. Set the current directory to xcom then invoke
javac -classpath . B.java
C. Set the current directory to test then invoke
javac -classpath . xcom/B.java
D. Set the current directory to test then invoke
javac -classpath xcom B.java
E. Set the current directory to test then invoke
javac -classpath xcom:. B.java


correct ans is "C"

Please explain this 2 me


With Regards<br /> <br /> varun
Aniket Patil
Ranch Hand

Joined: May 02, 2006
Posts: 218
The fundamental idea with packages and classpath is that your classpath needs to be the parent directory of the top-most directory in your package.

If your package hierarchy is A.B.C:

Then, your classpath needs to be the parent directory of A.

Option A: The default classpath being /foo, your topmost package directory needs to be a subdirectory of foo. However, class A is in package xcom which is not in subdirectory foo, hence class A will not be found.

Option B: Using "classpath ." asks the java compiler to look for class A in a subirectory of xcom (since the current directory is set to xcom). Since package xcom to which class A belongs cannot be a subdirectory of itself, class A cannot be found.

Option C: With the current directory test, the classpath . looks for class A in a subirectory of test, where package com exists and class A is found. You need to give the correct path to B.java here.

Option D: classpath xcom asks javac to look for class A in a subdirectory of xcom. This is similar to case B.

Option E: This would work, if the path to B.java is correct. javac looks for source files in the current directory which is set to test where class B cannot be found
[ January 25, 2007: Message edited by: Aniket Patil ]

SCJP 5.0 | SCWCD 1.4 <br /> <br />If you don't know where you are going, any road will take you there!
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Please read this and send a PM with the source of your mock question.


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Plz help me in solving the problem of JAVAC comand