当前位置:网站首页>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
边栏推荐
- Mécanisme d'attention du canal de fixation
- [structural mechanics] the reason why the influence line under joint load is different from that under direct load
- Ansible best practices playbook different context rights raising demo
- Seattention channel attention mechanism
- How to quickly install MySQL 5.7.17 under CentOS 6.5
- 汉泰示波器软件|汉泰示波器上位机软件NS-Scope,任意添加测量数据
- PostgreSQL has a cross database references are not implemented bug
- JSX的基本使用
- 热更新流程
- ECS 四 Sync Point、Write Group、Version Number
猜你喜欢

What are the ways to simulate and burn programs? (including common tools and usage)
![[structural mechanics] the reason why the influence line under joint load is different from that under direct load](/img/a6/fce0bb29cc5c84bc0ef20501617e06.png)
[structural mechanics] the reason why the influence line under joint load is different from that under direct load

Build a simple website by yourself

SEAttention 通道注意力機制

Here comes Wi Fi 7. How strong is it?

【HackTheBox】dancing(SMB)

Memo pattern

LabVIEW displays Unicode characters

Technical specifications of Tektronix tds3054b oscilloscope

Rapid development project -vscode plug-in
随机推荐
1016 part a+b
【代码随想录-哈希表】T15、三数之和-双指针+排序
什么是匿名内部类,如何使用匿名内部类
Five thousand years of China
Open source demo| you draw and I guess -- make your life more interesting
使用AssetStudio/UnityStudio UABE等
Why is the test post a giant pit? The 8-year-old tester told you not to be fooled
Research Report on the overall scale, major manufacturers, major regions, products and application segmentation of GPS antenna modules in the global market in 2022
泰克DPO4104数字荧光示波器技术参数
044. (2.13) add value to yourself
LabVIEW displays Unicode characters
【HackTheBox】dancing(SMB)
How to quickly change the database name in MySQL
Apifox: it is not only an API debugging tool, but also a collaboration artifact of the development team
Force deduction solution summary 324- swing sequencing II
[wc2021] Fibonacci - number theory, Fibonacci sequence
Log in to the MySQL database and view the version number on the command line
How to create a subtype like relationship between two generic classes when the classes are generic related
JDBC man Han building code
Idea modifying JVM memory