Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Package Problem

 
kaushik saha
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wrote a java program(named vechile.java) in a file in the package Automobile.

package Automobile;

public abstract class vechile
{
public abstract void speed();
}


Now in diffrent file but in a same package i wrote another java program (named car.java)

package Automobile;

public class car extends vechile
{
public void speed()
{
System.out.println("car specific speed");
}
}


My problem is that i can not compile car.java. The compiler error is "vechile class not found".

I have kept the two program in the Automobile folder.

And when compile then i write this way

f:/Automobile/>javac car.java;


why the second one is not compiling..

Please give me your valueable suggestion.
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Back out to the root directory that contains the Automobile folder and execute:

javac Automobile\car.java
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kausik,


Your problem is obvious!

Did you compile the Vehicle.java.

Because Car extends Vehicle so, javac finds Vehicle.class, that is not yet created. Dont think like javac finds for .java files.

You can do like this also;

> javac Vehicle.java Car.java

or

> javac Car.java Vehicle.java

Order doesn't matter here!


Does this help you?


Why do you go inside Automobile to just compile your .java
if no package exits, Automobile will automatically created when you
compile your source file.


You need to mention the full class name when executing you .class file:

> java Automobile.Car
or
? java Automobile/Car




Regards,
cmbhatt
[ April 11, 2007: Message edited by: Chandra Bhatt ]
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dont think like javac finds for .java files.

javac does find dependent .java files on the source path and compile them.
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

javac does find dependent .java files on the source path and compile them.



Then what is the case of Kaushik, why Vehicle not found. And very importantly referring to package while compiling is hard to swallow. Package is created when you compile the source if not already existing.

I found the obvious reason to answer because of the compiler error "Vehicle.class" not found. If your statement is right, why didn'y it compile Vehicle.java on which Car.java is dependent (Car extends Vehicle).


Please give your kind comments on this!

cmbhatt
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic