This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes K&B Chapter 10, Self test doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "K&B Chapter 10, Self test doubt" Watch "K&B Chapter 10, Self test doubt" New topic
Author

K&B Chapter 10, Self test doubt

Siri Naray
Ranch Hand

Joined: May 19, 2006
Posts: 105
This question is from K&B Chapter 10, Question 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?
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 current directory to test then invoke javac -classpath xcom B.java
E. Set current directory to test then invoke javac -classpath xcom:. B.java

The answer is C.
But if we give -classpath . the test directory will be searched for the .class file.
The answer should be D.
Can anyone help me understand where I am going wrong?
thank you
[ September 02, 2008: Message edited by: Sirisha Ghatty ]

If you worry you cannot work... If you work you need not worry
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18765
    
  40

The answer is C.
But if we give -classpath . the test directory will be searched for the .class file.
The answer should be D.
Can anyone help me understand where I am going wrong?


You forgot about the package. The classpath only specified the "top" directories. The class files are searched in subdirectories from the top, as defined by the package names.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Siri Naray
Ranch Hand

Joined: May 19, 2006
Posts: 105
Thank you I got it!!
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

I have a similar problem but nobody answered to mine. can anyone solve this
Problem pealse...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
 
Don't get me started about those stupid light bulbs.
 
subject: K&B Chapter 10, Self test doubt