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

Plz help me in solving the problem of JAVAC comand

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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


correct ans is "C"

Please explain this 2 me
 
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
The fundamental idea with packages and classpath is that your classpath needs to be the parent directory of the top-most directory in your package.

If your package hierarchy is A.B.C:

Then, your classpath needs to be the parent directory of A.

Option A: The default classpath being /foo, your topmost package directory needs to be a subdirectory of foo. However, class A is in package xcom which is not in subdirectory foo, hence class A will not be found.

Option B: Using "classpath ." asks the java compiler to look for class A in a subirectory of xcom (since the current directory is set to xcom). Since package xcom to which class A belongs cannot be a subdirectory of itself, class A cannot be found.

Option C: With the current directory test, the classpath . looks for class A in a subirectory of test, where package com exists and class A is found. You need to give the correct path to B.java here.

Option D: classpath xcom asks javac to look for class A in a subdirectory of xcom. This is similar to case B.

Option E: This would work, if the path to B.java is correct. javac looks for source files in the current directory which is set to test where class B cannot be found
[ January 25, 2007: Message edited by: Aniket Patil ]
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Please read this and send a PM with the source of your mock question.
    Bookmark Topic Watch Topic
  • New Topic