Java Internal classes

Source: Internet
Author: User
The role of the inner class

Java is a single inheritance, which implements multiple inheritance through an interface. When there is only an abstract class or a concrete class, and there is no interface, you can implement multiple inheritance with an anonymous inner class.

Internal class classification
  • Ordinary inner class
  • Anonymous inner class
  • Nested classes
Anonymous inner class
public class Demo {    prvivate int n;        public E make() {        return new E() {...};    }}

The return statement of the Make method means that the object is instantiated from the method body and then transformed upward into a reference to the base class E.

This reference must be decorated if we want to use the member reference of an external class inside the method body of an anonymous inner class final .

There are differences between multiple inheritance and interfaces through anonymous inner classes: instantiated objects resulting from multiple interface inheritance can be transformed upward into multiple target interfaces, whereas instantiated objects produced by anonymous inner classes can only be transformed upward into a single base class reference. That is, the multiple inheritance of an anonymous inner class is a subclass to a base class, and an interface is a subclass to multiple interfaces.

Nested classes

The inner class declared with static, which is often referred to as a nested class.

Objects whose perimeter classes are not required to create nested class objects, and non-static perimeter class objects cannot be accessed from objects in nested classes.

Java Internal classes

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.