wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Classpath - Question 1 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 1" Watch "Classpath - Question 1" New topic
Author

Classpath - Question 1

Edisandro Bessa
Ranch Hand

Joined: Jan 19, 2006
Posts: 584
Hi All,

The following question is from K&B Book.

Given the default classpath:

/foo

And this directory structure:


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

The correct answer is C. But what would happen if I removed the package declaration from two files above still leaving them in the same directory ?

Would the correct answer be B ?


"If someone asks you to do something you don't know how to, don't tell I don't know, tell I can learn instead." - Myself
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2841
    
  11

You can always just try these problems to see how they work. Basically, this one comes down to needing the classpath to be foo/test and being able to find the B.java file we want to compile.

Which allows B.java to compile? (Choose all that apply.)
A. Set the current directory to xcom
then invoke javac B.java

No good. You said the classpath was set to foo, not foo/test

B. Set the current directory to xcom
then invoke javac -classpath . B.java

Also no good. Now the class path is foo/test/xcom.

C. Set the current directory to test
then invoke javac -classpath . xcom/B.java

Good one. The classpath is foo/test and we tell javac where to find the file to compile.


D. Set the current directory to test
then invoke javac -classpath xcom B.java

No good at all. The classpath is wrong and javac can't find the file.


E. Set the current directory to test
then invoke javac -classpath xcom:. B.java

No good. The classpath is OK despite the extra entry, but javac can't find the file.


The correct answer is C. But what would happen if I removed the package declaration from two files above still leaving them in the same directory ?

Would the correct answer be B ?


Yes
 
Consider Paul's rocket mass heater.
 
subject: Classpath - Question 1
 
Similar Threads
difference b/w absolute path and relative paths
Confusing question on classpath please help
Plz help me in solving the problem of JAVAC comand
Classpath Query
Classpath Related Question