File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Inheritance problem in Eclipse Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Inheritance problem in Eclipse" Watch "Inheritance problem in Eclipse" New topic

Inheritance problem in Eclipse

Adam Blais

Joined: Dec 02, 2004
Posts: 27
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

Joined: Jun 13, 2000
Posts: 3340
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.

I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
san ch
Ranch Hand

Joined: Oct 18, 2004
Posts: 68

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 Source)
at Source)
at$100(Unknown Source)
at$ Source)
at Method)
at 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

Joined: Oct 18, 2004
Posts: 68
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

Joined: Aug 07, 2003
Posts: 1646
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

Joined: Dec 06, 2001
Posts: 3061
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 "". Notice that the capitalization is the same in both cases.


Java API Documentation
The Java Tutorial
I agree. Here's the link:
subject: Inheritance problem in Eclipse
It's not a secret anymore!