It's not a secret anymore!*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes classpath question in KnB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "classpath question in KnB" Watch "classpath question in KnB" New topic
Author

classpath question in KnB

liqiang yang
Ranch Hand

Joined: Jan 20, 2008
Posts: 92
5. 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

Ans:C

According to my thought:
Ans A-->complier can find B.java but not A.class
Ans B-->complier can find B.java and A.class("." stand for current dir that is xcom, A.class is really in there)
Ans C-->of course correct
Ans D&E-->complier cannot find B.java

It's make me confuse. Can anybody give a more detail explanation, especially why B is incorrect. Thanks.


DY.
SCJP 5.0 (100%), SCWCD 5.0 (79%), SCBCD 5.0 (preparing...)
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

This question is discussed in this thread. Let us know if you still have questions.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
liqiang yang
Ranch Hand

Joined: Jan 20, 2008
Posts: 92
Thanks marc!

I got it.
And I am not quite sure my thoughts about Ans A,C,D and E are fully correct. Can you double check any wrong with that. Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: classpath question in KnB
 
Similar Threads
Very Much Confused !!!
K&B Chapter 10, Self test doubt
Doubt in classpath statement....
Plz help me in solving the problem of JAVAC comand
Classpath Related Question