problem creating object of inner class in java

前端 未结 3 1427
隐瞒了意图╮
隐瞒了意图╮ 2020-12-17 00:39


Here is the code.

public class Test {
        class InnerClass{

               }

   public static void main(String[] args){
            InnerClass ic          


        
3条回答
  •  余生分开走
    2020-12-17 01:24

    First, a "nested" class is static, and an "inner" class is not.

    A static class is shared between all instances of the enclosing class (thus static fields are shared between all instances), while each instance has its own version of a non-static inner class.
    Non-static inner classes are stored with the enclosing object (rather than class) and can only be accessed via an instance.

提交回复
热议问题