Class in function

The statement Circle circle = new Circle(x, y, r); isn’t creating a class, but merely instantiating an already existing class.

Nonetheless, Java does allow us to create (a.K.a. define) a class or interface inside a function.

However, if it’s not based on an already existing class or interface, we can only return an instance of it as an Object datatype; which is pretty much useless in Java.

2 Likes