Outer class calls Inner class

Source: Internet
Author: User

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");
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.