Java Basics - Inner Classes

Disclaimer: The materials used in this column are written by VIP students of Kaige Academy. Students have the right to remain anonymous and have the right to final interpretation of the article. Kaige Academy aims to promote VIP students to learn from each other based on public notes.

Modular module: Also known as component research and development. The compressed package contains classes. When we write projects in the future, there may be some common codes. No matter what project you write, it is the same code. Repeated functions are packaged into a jar package, and whoever wants to use it in the future can just use it. Just like a car is composed of many parts, you can make these parts more general, and then those cars will be used. If necessary, just use it directly
www.apache.org  This is a non-profit organization, and there are some jar packages in it

Enumeration:
It is a new function of jdk1.5. It solves such a problem, as shown in the figure below: Give a number and return a content. For example, when you don't know what number to pass, apply for a few constants. In the future, you need to call Just choose, it's a selector, this is how the enumeration is written when it is still out.

image

After the enumeration is enumerated, the enumeration can tell you the type of the method. Just choose one with the enumeration type. Because its main function is to provide choice

image

image

Inner class:
Introduction: that is, a class is applying for a class, and there are also internal interfaces, internal abstract classes, and internal enumeration. Generally, internal classes are not allowed to be used by outsiders, so the establishment of internal classes Internal classes are divided into static and instance:
statically create new Test.T1();
Instance creates instance object.new T1();

image

Static inner classes
can have instance members
and static members

Instance inner class: can have instance members
but not static members

No matter how the operation class is written, a separate class file will be formed after compilation

Anonymous inner class:
that is, there is no name on the class, and an anonymous inner class can only access constants. It is like this. It is wasteful or troublesome to write a class with just one line of code in this file.

image

So there is an unnamed inner class, and curly brackets are written to indicate that the unnamed class implements this interface

image

image

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326503969&siteId=291194637