What is the purpose of creating static object in Java?

前端 未结 5 2059
走了就别回头了
走了就别回头了 2021-02-06 10:36
class Demo {
   void show() {
      System.out.println(\"i am in show method of super class\");
   }
}
class Flavor1Demo {

   //  An anonymous class with Demo as base c         


        
5条回答
  •  日久生厌
    2021-02-06 10:58

    In order to access methods or variables in main class without creating object in it,here we are defining anonymous inner class where we create object of static type so that its directly accessed from main class without creating the object.

提交回复
热议问题