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) {
    	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

Edited by DaniwebOS: n/a

5 Years
Discussion Span
Last Post by Paul Norris

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...

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.