inner class problem

inner class :

    Define class A inside class B, class A belongs to the inner class of B

    Features of inner class accessing outer class :

        It can directly access external members , including private

    How does the outer class access the members of the inner class ?

            Indirect access by creating inner class objects

Classification of inner classes :

    Member inner class : in the member position of the outer class

    Local inner class : in the local position of the outer class

Member inner class :

    Can directly access members of outer classes , including private

   The outer class wants to access the member methods of the inner class (non-static inner class):

        Format : outer class name. inner class name object name = outer class object. inner class object

Modifiers about member inner classes :

    private: role: to ensure the security of data!

    Static modification: You can treat a static inner class as a member of the outer class.

Features :

    A static member inner class accesses the data of the outer class, which must be statically modified

            For example : a person has a heart in the body


local inner class

    Members of the outer class that can access include private ...

    To access the show() of the inner class in the local position of the outer class, you need to create the inner class object in the local position and access it through the object

anonymous inner class

    The premise is that there is a class or interface

    This class can be a concrete class or an abstract class

    new class name or interface name {

    method override ();

}

    The essence of anonymous inner classes :

                It is a subclass object that inherits the class or implements the interface

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325891138&siteId=291194637