• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

K&B Chapter 10, Self test doubt

 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you I got it!!
 
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a similar problem but nobody answered to mine. can anyone solve this
Problem pealse...
 
We noticed he had no friends. So we gave him this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic