JAVA中的内部类与C++中的有什么不同?

解决方案 »

  1.   

    C++ 中的内部类只是一个名字命名机制.内部类和外部类之间不能直接访问对方成员.
    而java的内部类则是外部类的一部分.内部类作为外部类一部分,可以直接访问外部类私有变量.
      

  2.   

    Inner Classes
    • Added to Java™ Development Kit (JDK™) 1.1
    • Allow a class definition to be placed inside another
    class definition
    • Group classes that logically belong together
    • Have access to their enclosing class’s scope
    Properties of Inner Classes
    • You can use the class name only within the defined
    scope, except when used in a qualified name. The name
    of the inner class must differ from the enclosing class.
    • The inner class can be defined inside a method. Only
    local variables ed as final can be accessed by
    methods within an inner class.
    • The inner class can use both static and instance
    variables of enclosing classes and final local variables
    of enclosing blocks.
    • The inner class can be defined as abstract.
    • The inner class can have any access mode.
    • The inner class can be an interface that is implemented
    by another inner class