当前位置:网站首页>The difference between ordinary inner class and static inner class
The difference between ordinary inner class and static inner class
2022-04-23 18:56:00 【Mug mop fan】
Catalog
summary
First, let's talk about the definition of internal classes : Inner class is to declare another class in a class , Static inner classes are used when declaring inner classes “static” keyword . The author understands the main differences between them are as follows :
1. Declaration method
To instantiate an ordinary inner class , First, you need to instantiate the external class where it is located , Then instantiate the inner class ; Static inner classes can directly declare .
2. Variable types that can be defined or accessed
<1> Ordinary inner classes cannot declare static Variable of type , Static inner classes can ;
<2> After the instantiation of an ordinary internal class, it holds the reference of an external class object , Inside the ordinary inner class, you can access the variables and methods in the outer class ; Static internal classes do not hold references to external class objects after instantiation , Variables and methods in external classes cannot be accessed in static internal classes .
3. How the external class accesses the internal class
Static methods in external classes cannot create ordinary internal class objects , You can create static inner class objects ; Static inner classes and ordinary inner classes can be approximated as static variables and ordinary variables , Static methods cannot access ordinary variables .
4. summary
To make a long story short , In terms of coupling , Ordinary inner classes are highly coupled with outer classes , The coupling between static inner classes and outer classes is very low . Approximately speaking , Static inner classes are defined inside a class , Almost no difference from external classes .
——————————————————————
This article is updated to my official account. : Scan or wechat search “ Tea migration ” Can focus on . The background to reply “ The difference between ordinary inner class and static inner class ” You can get the push of this article . I also send some articles related to programming in official account. , Welcome to your attention ~
版权声明
本文为[Mug mop fan]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210603050045.html
边栏推荐
- Ctfshow - web362 (ssti)
- 12个例子夯实promise基础
- 解决:cnpm : 无法加载文件 ...\cnpm.ps1,因为在此系统上禁止运行脚本
- ESP32 LVGL8. 1 - calendar (calendar 25)
- 迁移学习进阶
- 2022.04.23(LC_763_划分字母区间)
- Scrollto and scrollby
- Screenshot using projectmediamanager
- Seata handles distributed transactions
- Résolution: cnpm: impossible de charger le fichier... Cnpm. PS1 parce que l'exécution de scripts est désactivée sur ce système
猜你喜欢
MySQL Téléchargement et installation de la version Linux
ESP32 LVGL8. 1 - bar progress bar (bar 21)
12个例子夯实promise基础
STM32: LCD显示
[mathematical modeling] - analytic hierarchy process (AHP)
Esp32 (UART receiving and sending) - receiving and sending communication of serial port (4)
Raspberry pie 18b20 temperature
Summary of actual business optimization scheme - main directory - continuous update
根据快递单号查询物流查询更新量
WebView opens H5 video and displays gray background or black triangle button. Problem solved
随机推荐
An 8266 crash
ESP32 LVGL8. 1 - arc (arc 19)
【C语言进阶11——字符和字符串函数及其模拟实现(2))】
Simple use of viewbinding
ctfshow-web362(SSTI)
Accessing private members using templates
Esp32 (UART receiving and sending) - receiving and sending communication of serial port (4)
Redis common interview questions
剑指 Offer II 116. 省份数量-空间复杂度O(n),时间复杂度O(n)
mysql_ Download and installation of Linux version
mysql_linux版本的下載及安裝詳解
纠结
ESP32 LVGL8. 1 - msgbox message box (msgbox 28)
2022.04.23 (the best time for lc_714_to buy and sell stocks, including handling charges)
Nacos as service registry
Nacos作为服务注册中心
Druid SQL和Security在美团点评的实践
#yyds干货盘点#stringprep --- 因特网字符串预备
Recyclerview control list item layout match_ Fundamental principle of parent attribute invalidation
Golang 语言实现TCP UDP通信