MyTriangle
is a non-static inner class. That means like all other instance members it (& it’s instance) belongs to an instance of the outer class as opposed to the class itself. Remember to belong to a class things need to be defined as static
.
Hence, you need to provide an outer class instance to instantiate the inner one as
new OuterClass().new MyTriangle();
If you mark the inner class static
which makes it nested it would allow you to refer to it in a static context like a public static main()
method.