How many times can classes be nested within a class?

前端 未结 6 1306
时光说笑
时光说笑 2020-12-31 13:49

I came across this questions on one of the online Java Tests. The options were 4,5,8 and any number of times.

I have only used one inner class, but have never tried

6条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-31 14:16

    I tried on my own: The answer is any number of times. The following is my test class, I had no compilation errors.

    
    public class Test {
    
    
        public Test ()
        {
    
        }
        public static void main (String args[])
        {
        new Test ();
        }
    
        class Test2
        {
            class Test3
            {
                class Test4
                {
                    class Test5{
                        class Test6{
                            class Test7{
                                class Test8{
                                    class Test9
                                    {
    
                                    }
                                }
                            }
                        }
                    }
                }
    
            }
    
        }
    
    
    }
    

提交回复
热议问题