The syntax format for defining internal classes (including static and non-static) variables outside of external classes is as follows:
Outerclass. innerclass varname
From the above syntax, we can see that when an internal class is used outside the external class, the complete Class Name of the internal class should
Outerclass. innerclass. Of course, if the external class has a package name, you should also add the package name prefix.
Because non-static internal class objects must be stored in external class objects, before creating non-static internal class objects, you must first
Create an object for its external class. The syntax for creating non-static internal class instances in the external class is as follows:
Outinstance. New innerconstructor ().
From the preceding syntax format, we can see that external class instances and new must be used to create non-static internal class instances outside the external class.
Call the constructor of a non-static internal class. BelowProgramHow to create non-static internal class objects outside the external class, and
Assign it to a variable of the non-static internal class type.
class out {
// defines an internal class without the access control operator, that is, other classes in the same package can access this internal class
class in {
Public in (string MSG) {
system. out. println (MSG);
}< BR >}< br> public class createinnerinstance {
Public static void main (string [] ARGs) {
out. in in = new out (). new in ("test information");
}< BR >}< br>