• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

K&B Chapter 10, Self test doubt

 
Siri Naray
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Henry Wong
author
Marshal
Pie
Posts: 21190
80
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Siri Naray
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you I got it!!
 
Ankit Garg
Sheriff
Posts: 9521
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a similar problem but nobody answered to mine. can anyone solve this
Problem pealse...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic