当前位置:网站首页>What is an anonymous inner class and how to use it
What is an anonymous inner class and how to use it
2022-06-29 04:34:00 【zhang__ one thousand two hundred and thirty-four】
- An anonymous inner class is a definition of a class , At the same time, it is also an object , It has the characteristics of defining classes , There are also features of creating objects
class outer05{
private int n1=100;
public void f2(){
// Anonymous inner class based on class
person person = new person(){
@Override
public void hi() {
System.out.println(" Rewrote hi Method ");
}
};
person.hi();// Dynamic binding The real type of operation is outer05$1
new person(){
@Override
public void say1(String name) {
super.say1(name);
}
}.say1("jack");/* You can do this without creating an object .say()*/
}
}
class person{
public void hi(){
}
public void say1(String name){
System.out.println("haha"+name);
}
}
- You can directly access all members of an external class , Including private
- Cannot add access modifier , Because its status is a local variable
- Scope : Just defining its methods or code blocks
- Anonymous inner class – visit –> External class members
- External other classes – Cannot access –> Anonymous inner class
- If the members of the outer class and the inner class have the same name , Internal class access , By default, follow the principle of proximity , If you want to access members of an external class , You can use ( External class name .this. member ) To visit
This article explains very clearly
https://blog.csdn.net/a850661962/article/details/109642780
边栏推荐
- The 30th day of force deduction (DP topic)
- ROS URDF model is parsed into KDL tree
- Call snapstateon closed sou from Oracle CDC
- 【HackTheBox】dancing(SMB)
- Analysis on the types of source code anti leakage technology
- Memo pattern
- Log in to the MySQL database and view the version number on the command line
- The virtual machine MySQL cannot be connected to the local computer
- 力扣解法汇总324-摆动排序 II
- String differences between different creation methods
猜你喜欢

The 30th day of force deduction (DP topic)

Build a simple website by yourself

直播预约|AWS Data Everywhere 系列活动

Technical specifications of Tektronix tds3054b oscilloscope
![[hackthebox] dancing (SMB)](/img/bb/7bf81004b9cee80ae49bb0c0c2b810.png)
[hackthebox] dancing (SMB)

JVM_ 16_ Garbage collector

PostgreSQL has a cross database references are not implemented bug

Observer pattern

Here comes Wi Fi 7. How strong is it?

Analysis of moudo Network Library
随机推荐
[new function] ambire wallet integrates Metis network
The five levels of making money, which level are you on?
直播预约|AWS Data Everywhere 系列活动
【HackTheBox】dancing(SMB)
What are the circular statements of MySQL
Ansible best practices playbook different context rights raising demo
Lua protobuff Emmy Lua wheel
LabVIEW显示Unicode字符
网传广东一名学生3次考上北大,3年共赚200万元奖金
Mediator pattern
项目开发修养
Redis cache penetration, cache breakdown, cache avalanche
Basic use of JSX
Remediation for Unsafe Cryptographic Encryption
Rapid development project -vscode plug-in
SEAttention 通道注意力机制
Why is the test post a giant pit? The 8-year-old tester told you not to be fooled
My creation anniversary
力扣解法汇总324-摆动排序 II
Here comes Wi Fi 7. How strong is it?