Win a copy of Terraform in Action this week in the Cloud 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Inheritance problem in Eclipse

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic