当前位置:网站首页>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();
}
}
边栏推荐
猜你喜欢

zabbix监控系统自定义监控内容

Famous blackmail software stops operation and releases decryption keys. Most hospital IOT devices have security vulnerabilities | global network security hotspot on February 14

Snipaste convenient screenshot software, which can be copied on the screen

Guanghetong's high-performance 4g/5g wireless module solution comprehensively promotes an efficient and low-carbon smart grid

NPM run build error
![[go basics] 1 - go go](/img/e2/d973b9fc9749e1c4755ce7d0ec11a1.png)
[go basics] 1 - go go

【Go基础】2 - Go基本语句

一文了解数据异常值检测方法

Mouse over to change the transparency of web page image

Heap concept in JVM
随机推荐
运动【跑步 01】一个程序员的半马挑战:跑前准备+跑中调整+跑后恢复(经验分享)
谷歌官方回应:我们没有放弃TensorFlow,未来与JAX并肩发展
Laravel page load problem connection reset - PHP
ZABBIX monitoring system custom monitoring content
Div hidden in IE 67 shows blank problem IE 8 is normal
Activiti common operation data table relationship
Redis sentinel mechanism
A method for detecting outliers of data
Leetcode 146. LRU 缓存
C#实现一个万物皆可排序的队列
DM8 command line installation and database creation
Azure ad domain service (II) configure azure file share disk sharing for machines in the domain service
Email alarm configuration of ZABBIX monitoring system
Do you know about autorl in intensive learning? A summary of articles written by more than ten scholars including Oxford University and Google
SSRF vulnerability exploitation - attack redis
es6总结
1. Kalman filter - the best linear filter
Go h*ck yourself:online reconnaissance (online reconnaissance)
团体程序设计天梯赛-练习集 L1-006 连续因子
Common components of flask