如何在扩展 class 中使用方法并在主 class 中使用它们

How to use methods in extended class and use them in main class

我正在尝试创建一个扩展形状的方法 class 并使用它,但它不起作用。 这是我正在尝试做的代码:

public class Try extends Application {
    @Override
    public void start(Stage arg0) throws Exception {
        Rectangle rectangle = new customRectangles(5);
        int i = rectangle.getObject();   //This doesn't work
        System.out.println(i);
    }
    
    class customRectangles extends Rectangle {
        int object = 0;

        customRectangles(int object){
            this.object = object;
        }

        public int getObject(){
            return object;
        }
    }
}

这不是完整的代码,其中大部分已被删除。我在网上搜索过,找不到任何东西,所以来问这个问题。请帮忙。

Rectangle rectangle = new customRectangles(5);

表示变量矩形只会是一个矩形。因此只会看到 Rectangle 方法。你想完成什么:

customRectangles rectangle = new customRectangles(5);

(Class 名称应以大写字母开头)