当前位置:网站首页>Internal learning
Internal learning
2022-07-04 08:25:00 【weixin_ fifty-three million fifty thousand one hundred and eigh】
Classification of internal classes : Member inner class ( Static inner class and non static inner class ), Local inner classes don't talk about modifiers , Anonymous inside
class .
1. Member inner class
A member inner class is equivalent to a member of a class :
Different from the outer class , Inner classes can be declared as private perhaps protected;
You can call members of external classes .
The inner class of the member is the member of the class :
You can define attributes in internal classes , Method , Constructors, etc
Can be declared as abstract class , So it can be inherited by other inner classes
Can be declared as final Of
Generate external classes after compilation $ Inner class .class Bytecode file ( Applicable to local inner classes )
Be careful :
1. Not static Members in inner classes cannot be declared as static Members of , Only in external classes or static Can only be declared in a member's inner class static member .
2. External classes access members, members of inner classes , Inner class object . The way members are .
3. Member inner classes can directly use all members of outer classes , Including private data
Inner classes can be declared as abstract classes , So it can be inherited by other inner classes , You can also state final Of .
Why use inner classes : Each inner class can independently inherit a ( Interface , abstract class ) Internship , So whether or not the outer class has inherited a certain ( Interface , abstract class ) Realization , No effect on inner classes . Sometimes in program design, there are some problems that are difficult to solve using interfaces , At this time, you can make use of the , The ability to inherit multiple concrete or abstract classes . Interface only solves most problems , The inner class makes the solution of multiple inheritance more complete . The biggest advantage of using inner classes is that it can solve the problem of multiple inheritance very well .
( The static ) Member inner class :
Outer outer=new Outer();
Outer.Inner inner=outer.new Inner();
( static state ) Member inner class :
Outer.Inner inner=new Outer.Inner();
2. Local inner classes
Local class scope : Code block , Constructors , Method .
The local class is still a separate class , After compilation, the inner class will be compiled to be independent .class file , But the front is preceded by the outside
Class name and $ Symbol , And numbers .
Local inner classes and local variables have similar status , Out of commission public,protected, default ,private
Local inner classes cannot use static modification , So you can't include static members either
Local inner classes can use members of external classes , Including private
Local inner classes can use local variables of external methods , But it must be final Of . It consists of declarations of local inner classes and local variables
Due to different periods .
3. Anonymous inner class
An anonymous class , Is a class without a name , Its name is given by Java Given by compiler , Anonymous classes cannot use any keywords and access control characters , The access rules of anonymous classes and local classes are the same .
interface Inner {
void say();
}
public class Test{
public static void main(String[] args) {
person(new Inner(){
@Override
public void say() {
System.out.println("java");
}
});
}
public static void person(Inner an){
an.say();
}
}
边栏推荐
- Azure ad domain service (II) configure azure file share disk sharing for machines in the domain service
- How to improve your system architecture?
- 1、卡尔曼滤波-最佳的线性滤波器
- 2022 examination questions for safety managers of metal and nonmetal mines (underground mines) and examination papers for safety managers of metal and nonmetal mines (underground mines)
- 线性代数1.1
- Thesis learning -- time series similarity query method based on extreme point characteristics
- 小程序容器技术与物联网 IoT 可以碰撞出什么样的火花
- PHP converts seconds to timestamps - PHP
- Leetcode 146. LRU 缓存
- 真空介电常数和真空磁导率究竟是由什么决定的?为何会存在这两个物理量?
猜你喜欢
SSRF vulnerability exploitation - attack redis
Moher college phpMyAdmin background file contains analysis traceability
How to improve your system architecture?
[go basics] 2 - go basic sentences
Introduction to neural network (Part 2)
广和通高性能4G/5G无线模组解决方案全面推动高效、低碳智能电网
Newh3c - routing protocol (RIP, OSPF)
ctfshow web255 web 256 web257
Easy to understand: understand the time series database incluxdb
ZABBIX monitoring system custom monitoring content
随机推荐
【性能测试】一文读懂Jmeter
Use preg_ Match extracts the string into the array between: & | people PHP
弈柯莱生物冲刺科创板:年营收3.3亿 弘晖基金与淡马锡是股东
Heap concept in JVM
How to use MOS tube to realize the anti reverse connection circuit of power supply
【性能測試】一文讀懂Jmeter
PCIE知识点-010:PCIE 热插拔资料从哪获取
根据数字显示中文汉字
Take you to master the formatter of visual studio code
Relations courantes de la fiche de données d'exploitation pour les activités
Fault analysis | MySQL: unique key constraint failure
Convert datetime string to datetime - C in the original time zone
OKR vs. KPI 一次搞清楚这两大概念!
1. Getting started with QT
OKR vs. KPI figure out these two concepts at once!
Newh3c - routing protocol (RIP, OSPF)
FRP intranet penetration, reverse proxy
SQL statement view SQL Server 2005 version number
Activiti常见操作数据表关系
Difference between static method and non static method (advantages / disadvantages)