Access control

xiaoxiao2021-03-06  64

1. Access control modifier:

Private default protected public PUBLIC

Similar 1 1 1 1 1

With bag 1 1 1

Subclass 1 1

Other bags 1

Access control of class members, the class itself also has access control, but the class itself has only two access control, which is public and default.

The parent class can't be private and default otherwise the word class cannot inherit.

2, internal class:

Class Class Class C class, then B is known, but it is not known for the outside. There is no special place for the definition of the internal class, he can

Direct access to all variables and methods of reference external classes, the difference is that internal classes can be declared as private or protected

EG:

Class Outer

{

INT OUTER_I = 100;

Void test ()

{

INNER IN = New Inner ();

In.display ();

}

Class Inner

{

Void Display ()

{

System.out.println ("Display: Outer_i =" Outer_i);

}

}

}

Class InnerClassDemo

{

Public static void main (string [] args)

{

Outer outer = new outer ();

Outer.test ();

}

}

转载请注明原文地址:https://www.9cbs.com/read-89348.html

New Post(0)