Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

inheritance problem?

 
Ranch Hand
Posts: 37
  • 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
 
Ranch Hand
Posts: 3244
  • 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
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • 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
  • 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
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • 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
  • 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
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • 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
  • 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
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • 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
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic