• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Question about classpath from K&B book

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm getting another doubt.this is frm k&B book

chapter 10 question 3
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

Answer:C

Explanation in book:

classpath isn't looking for B.java its looking for whatever classes B.java needs


I don't understand why A> and B> are wrong..
In xcom directory if we are giving command "javac B.java" then it should compile since B.java and A.class both are present in that directory.But it doesn't happen so.
If B.java doesn't need other class files then A> and B> works f9 but if it needs class files as of here it needs A.class so it doesn't work...
I can't understand properly.
please explain in detail...

thanks
with regards
sawan
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
While A and B are in that directory, the first two choices would only work if you removed the package statements. "package xcom" is a statement that Java expects them to be in an xcom directory underneath the working directory (or in a jar file or on the classpath.)
 
Sawan Mishra
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Boyarsky
But if there is A.java file present in the same directory and if I compile then A.java with the command "javac A.java",it compiles but "javac B.java" doesn't.
As B extends from another class file present in the same package it doesn't compile. why??

reply
    Bookmark Topic Watch Topic
  • New Topic