How is it possible to create a sub class object within it's base class?

后端 未结 5 1628
自闭症患者
自闭症患者 2021-01-25 17:38
class arijit
{
 public static void main(String args[])
 {
  System.out.println(\"Base class main\");
  amit ab=new amit(); //how is it possible as the sub class object a         


        
5条回答
  •  走了就别回头了
    2021-01-25 18:20

    Perhaps you need to distinguish compile time from runtime.

    At compile time the structure of arijit is well-known. It does not matter that halfway in the class, in main, a subclass is used, as that is a runtime thing.

    But I admit, the Java compiler is not all that stupid :)

提交回复
热议问题