File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

inheritance problem?

 
jordan gong
Ranch Hand
Posts: 37
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3244
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
jordan gong
Ranch Hand
Posts: 37
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7610
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 37
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7610
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 37
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes Sir, it works now!
I need to set my classpath correctly.
Thank you so much!
jordan
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by jordan gong:
[B]Yes Sir

you are a funny guy

------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic