aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes inheritance problem? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "inheritance problem?" Watch "inheritance problem?" New topic
Author

inheritance problem?

jordan gong
Ranch Hand

Joined: Jun 12, 2001
Posts: 37
I have a funny inheritance problem here, which I could not understand why.
I put two java files in the "same folder", one extends the other.
The first one is:
public class New0 extends Object{}
I compiled it, no problem.
The second one is:
public class New1 extends New0{}
Now, I got error message when I try to compile this one.
The error message shows:
C:\com\cancal\New1.java:2: cannot resolve symbol
symbol : class New0
location: class New1
public class New1 extends New0
^
1 error
Tool completed with exit code 1
Why the second java file cannot recoganize the first class file?They are in the same folder and they are both public. I tried to put "package com.cancal;" in each file, but still does not work
Looking for help.
Thanks
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Jordan
In one file you can only have one public class. Try making the second class default (no modifier) and it should compile.

------------------
Dave
Sun Certified Programmer for the Java� 2 Platform


Dave
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
try to compile with the -classpath switch
Let's say the directory where your files are is c:\xyz
then try compiling with
javac -classpath c:\xyz New1.java
HIH


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
jordan gong
Ranch Hand

Joined: Jun 12, 2001
Posts: 37
Thank you Dava and HIH!
HIH, you are right, after I tried javac -classpath :\com\cancal\New1.java, it works.
So the problem is the classpath, right?
But now the problem is, I could not find the class files in the same folder. Where does the New1.class file reside in this case?
thanks.
jordan
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
First, HIH means Hope It Helps. My name is Valentin as written on the left of the page... Never mind
When you compiled the source you should end up with the class file in the same directory.
You should have:
c:\xyz\New0.java
c:\xyz\New0.class
c:\xyz\New1.java
c:\xyz\New1.class
Is it not the case ?

------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform
jordan gong
Ranch Hand

Joined: Jun 12, 2001
Posts: 37
Mr.Valentin:
No, it is not the case. After I compiled those files, I refresh the folder, but can only see the java files, no class file.
Maybe JVM default the class files to certain place?
thanks.
jordan
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Jordan, don't call me Mr, JavaRanch is a friendly place
no the class files have to be there unless you specify the -d option on the command line. That's weird...
remove all files except the source from the directory and compile again with javac -classpath . *.java
Note that . denotes the current directory.
------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform
[This message has been edited by Valentin Crettaz (edited November 28, 2001).]
jordan gong
Ranch Hand

Joined: Jun 12, 2001
Posts: 37
Yes Sir, it works now!
I need to set my classpath correctly.
Thank you so much!
jordan
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Originally posted by jordan gong:
[B]Yes Sir

you are a funny guy

------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform
 
Consider Paul's rocket mass heater.
 
subject: inheritance problem?