当前位置:网站首页>2021-05-12 internal class
2021-05-12 internal class
2022-06-23 10:07:00 【Deer like deer】
Inner class
Inner class is to define a class within a class
- Member inner class
- Static inner class
- Local inner classes
- Anonymous inner class
Member inner class
package oop.demo12;
public class Outer {
private int id=10;
public void out(){
System.out.println(" This is the method of the outer class ");
}
public class Inner{
public void in(){
System.out.println(" This is the method of the inner class ");
}
// The inner class accesses the private properties of the outer class
public void getID(){
System.out.println(id);
}
}
}
// One java There can be more than one class class , But there can only be one public class
package oop.demo12;
public class Application {
public static void main(String[]args){
//new Instantiation
Outer outer = new Outer();
// To instantiate an internal class, you need to instantiate the internal class through the external class of the internal class
Outer.Inner inner = outer.new Inner();
inner.in();
// The private properties of the external class are accessed through the internal class
inner.getID();
}
}
Static inner class
package oop.demo12;
public class Outer {
private static int id=10;//Inner yes static,id It's going to change to static
public void out(){
System.out.println(" This is the method of the outer class ");
}
public static class Inner{
public void in(){
System.out.println(" This is the method of the inner class ");
}
// The inner class accesses the private properties of the outer class
public void getID(){
System.out.println(id);
}
}
}
Local inner classes
package oop.demo12;
public class Outer {
public void method(){
class Inner{
// Local inner classes ( It is the same as the local variables in the method )
public void in(){
}
}
}
}
Anonymous inner class
package oop.demo12;
public class Test {
public static void main(String[] args) {
// No name to initialize the class You don't have to save instances to variables
new Apple().eat();
UserService userService = new UserService(){
@Override
public void Hello() {
}
};
}
}
class Apple{
public void eat(){
System.out.println("1");
}
}
interface UserService{
public void Hello();
}
边栏推荐
- Subscript operator of map
- 太无奈!微软停售 AI 情绪识别等技术,直言:“法律跟不上 AI 的发展”
- Bioinformatics | 基于相互作用神经网络的有效药物-靶标关联预测
- Unity技术手册 - 形状(Shape)子模块 - Sprite、SpriteRenderer及生命周期内速度(Velocity over Lifetime)
- Comic | code review is driving me crazy!
- Fill the pit for repvgg? In fact, it is the repoptimizer open source of repvgg2
- [GXYCTF2019]BabySQli
- 表单重复提交问题
- mysql innodb 的 redo log buffer 中未 commit 的事务持久化到 redo log 后,万一事务 rollback 了怎么办?redo log 怎么处理这个事务操作?
- 同花顺推荐么?手机开户安全么?
猜你喜欢

ICLR 2022 | dynamic convolution tadaconv in video and efficient convolution video understanding model tadaconvnext

Nuxt.js spa与ssr的区别

Shengshihaotong enables high-quality development with industrial Digitalization

oracle中遇到的bug

Go 字符串比较

利用华为云ECS服务器搭建安防视频监控平台

SQL create a new field based on the comparison date

2021-05-07构造器

The era of copilot free is over! The official version is 67 yuan / month, and the student party and the defenders of popular open source projects can prostitute for nothing

RT thread add MSH command
随机推荐
基於STM32設計的寵物投喂器
Bioinformatics | effective drug target correlation prediction based on interacting neural network
The second Tencent light · public welfare innovation challenge was launched, and the three competition topics focused on the social value of sustainable development
Getting started with cookies and sessions
Three implementation methods of distributed lock
快速排序的简单理解
Liujinhai, architect of zhongang Mining: lithium battery opens up a Xintiandi for fluorine chemical industry
谷贱伤农,薪贱伤码农!
thymeleaf中如何给onclick事件传值的方法
Bugs encountered in Oracle
Successful experience of postgraduate entrance examination in materials and Chemical Engineering (metal) of Beijing University of Aeronautics and Astronautics in 2023
Simple understanding of quick sort
高性能算力中心 — RDMA — 实现技术
在OpenCloudOS使用snap安装.NET 6
How to pass values to onclick events in thymeleaf
用贪吃蛇小游戏表白(附源码)
2022 Gdevops全球敏捷运维峰会-广州站精华回放(附ppt下载)
2021-05-11instanceof和类型转换
高性能算力中心 — InfiniBand — Overview
Form repeated submission problem