superclasses

publicvoid calculateArea(double area)

{

area = width * height / 2;

}

I have the above code in a seperate class to my super class, i have already done my constructor above this and called the super class in that fine. e.g.super(width, height);

whatever i try for this void method it will not let me access the width and height as they are in the super class, a was wondering the way to solve this so it works! pls.

[636 byte] By [bishaw_no1a] at [2007-11-26 20:13:57]
# 1

you could make those variables protected rather than private, although arguably that violates encapsulation. you could also provide getter methods for your superclass to return those values, and call them from within the method you posted. eg

public void calculateArea(double area) {

area = getWidth() * getHeight() / 2;

}

georgemca at 2007-7-9 23:20:14 > top of Java-index,Java Essentials,New To Java...
# 2
thanks! that was a simple mistake, a already had them get methods in my super class a just needed to call them, ta!
bishaw_no1a at 2007-7-9 23:20:14 > top of Java-index,Java Essentials,New To Java...
# 3

//Returns a string representing the values of all the attributes of the triangle

public String toString()

{

return height + width +"Triangle Style is: "+ triangleStyle;

}

i know for this return string method u have to use something along the lines of return super.toString()

the triangleStyle is fine as it is only in my triangle class its the other 2 again that wont access.

1 i have compiled this correctly my whole program should work correctly!

sorry 4 been a pain

bishaw_no1a at 2007-7-9 23:20:14 > top of Java-index,Java Essentials,New To Java...