File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

classpath question in KnB

 
liqiang yang
Ranch Hand
Posts: 92
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question is discussed in this thread. Let us know if you still have questions.
 
liqiang yang
Ranch Hand
Posts: 92
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic