The syntax format for defining internal classes (both static and Non-static) is as follows outside the outer class:
Outerclass.innerclass VarName
As you can see from the syntax above, when you use an inner class outside of the outer class, the complete class name of the inner class should
Outerclass.innerclass. Of course, if the outer class has a package name, you should also increase the package name prefix.
Because objects of non-static inner classes must be in the object of an external class, creating a non-static inner class object must be preceded by
The object that created its outer class. The syntax for creating Non-static internal class instances where the outer class is assumed is as follows:
Outinstance.new Innerconstructor ().
As you can see from the above syntax format, creating a non-static inner class instance outside of a class must use an external class instance and new to
Calls the constructor of a non-static inner class. The following program teachers how to create objects of non-static inner classes outside of external classes, and
Assign it to a variable of a non-static inner class type.
Class out{
Defines an inner class that does not use an access control character, that is, other classes in the same package can access the inner class
Class in{
Public in (String msg) {
SYSTEM.OUT.PRINTLN (msg);
}
}
}
public class createinnerinstance{
public static void Main (string[] args) {
Out.in in = new Out (). New IN ("Test Information");
}
}