So my goal is to use inheritance and as you can see I inherited Point Example which has x, y as variables. Well for some odd reason my Length seems to be in correct and I'm not sure where I went wrong. Any guidance will be very much appreciated.


Just updated the code and found some more errors that I just fixed... now there are warnings that won't allow me to run the program?...

class PointExample {

    private double x;
    private double y;

    public PointExample(double a, double b) {
        x = a;
        y = b;
    }
}

class Length extends PointExample {

    private double middleLength;
    private double leftLength;
    private double rightLength;

    public Length(double a, double b, double c) {
    	super(a,b);
    	leftLength = a;
    	middleLength = b;
        rightLength = c;
    }

public class InheritanceTest {

    public void main(String args[]) {

        Length a = new Length(14, 9, 15);
        double overallMiddle = rightLength - middleLength;
    	System.out.println("The right length - the middle length = " + overallMiddle);
    }
}
}

Error received
http://i42.tinypic.com/e12cqo.png

Recommended Answers

All 4 Replies

Any help or idea?

considering you don't have a valid main method .. how did you get it to run in the first place?

considering you don't have a valid main method .. how did you get it to run in the first place?

how do i not have a valid main method?

You need an extra close brace after the constructure in class Length. And take out the extra brace on the very last line. The way your code is, the public class InheritanceTest is a nested inner class within Length. I reckon that's what stultuske was talking about.

Other than that, your code should work...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.