当前位置:网站首页>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
边栏推荐
- SSDB基础1
- Actual combat of Nacos as service configuration center
- ESP32 LVGL8. 1 - textarea text area (textarea 26)
- Click the input box to pop up the keyboard layout and move up
- STM32: LCD display
- The type initializer for ‘Gdip‘ threw an exception
- On iptables
- How can programmers quickly develop high-quality code?
- Configure iptables
- SQL中函数 decode()与 replace()的用法
猜你喜欢
PyGame tank battle
7、 DOM (Part 2) - chapter after class exercises and answers
Machine learning theory (8): model integration ensemble learning
Raspberry pie 18b20 temperature
STM32: LCD display
[today in history] April 23: the first video uploaded on YouTube; Netease cloud music officially launched; The inventor of digital audio player was born
MVVM模型
MySQL Téléchargement et installation de la version Linux
ESP32 LVGL8. 1 - msgbox message box (msgbox 28)
mysql_ Download and installation of Linux version
随机推荐
22 year flying Book manpower Kit
Chondroitin sulfate in vitreous
Download xshell 6 and xftp6 official websites
Esp32 (UART receiving and sending) - receiving and sending communication of serial port (4)
Use bitnami / PostgreSQL repmgr image to quickly set up PostgreSQL ha
The type initializer for ‘Gdip‘ threw an exception
Nacos cluster construction and MySQL persistence configuration
After opening the original normal project, the dependency package displays red and does not exist.
2022.04.23(LC_763_划分字母区间)
Golang 语言实现TCP UDP通信
Simple use of navigation in jetpack
[today in history] April 23: the first video uploaded on YouTube; Netease cloud music officially launched; The inventor of digital audio player was born
ESP32 LVGL8. 1 - img picture (IMG 20)
The corresponding permissions required to automatically open the app in the setting interface through accessibility service
C: generic reflection
Teach you to quickly rename folder names in a few simple steps
ESP32 LVGL8. 1 - arc (arc 19)
Esp32 (UART ecoh) - serial port echo worm learning (2)
解决:cnpm : 无法加载文件 ...\cnpm.ps1,因为在此系统上禁止运行脚本
中金财富怎么样?在上边开户安全吗