• 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:

Classpath - Question 1

 
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?
 
Sheriff
Posts: 3064
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Everybody's invited. Except this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic