Instantiating object from inside the main of that class in Java

前端 未结 5 971
萌比男神i
萌比男神i 2020-12-08 15:58

I was looking through my OOP class documentation and I found this example:

class Student {
    private String name;
    public int averageGrade;


    public         


        
5条回答
  •  庸人自扰
    2020-12-08 16:12

    This is just fine.

    I know it looks a bit recursive, but what happens is that the main() method gets called when you launch this class from the command line, and then the constructor gets called when you actually instantiate an instance of the object. (See Jon's comment as well.)

提交回复
热议问题