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 in Eclipse

 
Adam Blais
Greenhorn
Posts: 27
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an assignment with a class called CircleCalculatorA that calculates the third side as well as all the angles of a triangle. This is the constructor:



We then need to write a class that extends this one and calculates the area and perimeter. This is what I have so far for the class.



In perimeter = a + b + c;, a, b, and c are underlined in red and it says that "field is not visible". I have no idea what this means. Ever since we've been doing inheritance I've been going insane. I can't stand Java anymore.
 
Carl Trusiak
Sheriff
Posts: 3340
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have left out the declaration of the instance variables a, b and c from this code. But, my guess is you have them as private.



private variables are not visible in sub classes. Also if the classes are in 2 different pacakges and you have the access a default



Change these to public or protected and try again.
 
san ch
Ranch Hand
Posts: 68
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey

iam having the same problem with inheritance when i use the ecllipse ide


when the above code is run in eccllipse it give the folowing errors
i get the following errors
java.lang.NoClassDefFoundError: A (wrong name: a)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Exception in thread "main"


but when i use the jdk from cmd it works fine .

i believe i need to do some setting changes in ecllipse but i dont know wht to do
 
san ch
Ranch Hand
Posts: 68
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oops sorry

in the code while executing i have taken of the comments from line 37 to 46 .....forgot doing tha in the code i posted
 
David Harkness
Ranch Hand
Posts: 1646
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adam, if the class you were given, TriangleCalculatorA, has accessor methods for the sides (getA, getB, getC), you can use those instead of referencing the variables directoy, assuming they have a visible scope (generally public).

San, I assume you don't specify a package for your classes. If not, perhaps Eclipse is having trouble realizing they are in the same (non-existent) package. It's always a good idea to put your classes into named packages.
 
Layne Lund
Ranch Hand
Posts: 3061
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
san ch, the error message gives you a hint as to what is wrong:

Notice that it indicates that the class named "A" cannot be found. The name "a" was found, though. This typically means that the name of the class and the name of the file it is saved in do not match. Remember that Java is case-sensitive, so the file name HAS to match EXACTLY, especially when it comes to capitalization. This means that "public class A" must be saved in a file named "A.java". Notice that the capitalization is the same in both cases.

Layne
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic