Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2006

Tip: Looking for answers? Try searching our database.

How can I inherit a class in Bean with package?

Thread view: 
Sarah - 18 Jan 2006 11:34 GMT
Can anyone please help me. Im having a problem to compile class RedCar.
It gives no error when I remove package.com.MyCar line. Class Car works
fine.
-----------------------------
package com.MyCar;

class Car{
   protected int total;

   public Car(){  this.total = 10; }
   }
}
------------------------------
package com.MyCar;

class RedCar extends Car{
   public RedCar(){}

   public void getTotal(){ System.out.print("Total car:" + total); }
}
-----------------------------
I need these files for my Bean project. The error is: cannot find
symbol class Car
Thomas Hawtin - 18 Jan 2006 12:05 GMT
> Can anyone please help me. Im having a problem to compile class RedCar.
> It gives no error when I remove package.com.MyCar line. Class Car works
> fine.

Looks like the source (or sourcepath) is in the wrong place.

The files should be in files com/MyCar/Car.java and com/MyCar/MyCar.java
relative to the sourcepath (which is usually the current directory).

Both files will need to be in the same package as the base class is not
public.

BTW, package names should be all lower case, and preferably a single word.

Tom Hawtin
Signature

Unemployed English Java programmer
http://jroller.com/page/tackline/

Sarah - 18 Jan 2006 14:15 GMT
Usually I put my java files in jdk/bin directory, compile them, then
transfer them to package.

Referring to my problem, is there a way that I can compile those files
from the package?

Btw I have changed the package names.Thanks for the reminder.
John C. Bollinger - 19 Jan 2006 02:04 GMT
> Usually I put my java files in jdk/bin directory, compile them, then
> transfer them to package.

You will eventually find that this approach is too unwieldy to continue
using; this will probably happen sooner rather than later.  In the mean
time...

> Referring to my problem, is there a way that I can compile those files
> from the package?

I'm not sure quite what you mean about compiling files "from the
package."  If you want to do the compilation as you describe above then
you can do so by first compiling the Car class, then putting it in an
appropriate (corresponding to the package) directory, then compiling the
RedCar with use of the compiler's classpath option to tell it the base
directory(-ies) in which to look for compiled classes.

If you want to do it the way most of the world does it (directly or
indirectly) then refer to Tom's response.

Signature

John Bollinger
jobollin@indiana.edu



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.