当前位置:网站首页>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
边栏推荐
- 纠结
- 在渤海期货办理开户安全吗。
- 2022.04.23 (lc_763_divided into letter interval)
- Raspberry pie uses root operation, and the graphical interface uses its own file manager
- std::stoi stol stoul stoll stof stod
- PyGame tank battle
- 根据快递单号查询物流查询更新量
- 2022.04.23 (the best time for lc_714_to buy and sell stocks, including handling charges)
- SSDB基础1
- C: generic reflection
猜你喜欢
Query the logistics update quantity according to the express order number
ctfshow-web362(SSTI)
剑指 Offer II 116. 省份数量-空间复杂度O(n),时间复杂度O(n)
One of the reasons why the WebView web page cannot be opened (and some WebView problem records encountered by myself)
【C语言进阶11——字符和字符串函数及其模拟实现(2))】
Esp32 drive encoder -- siq-02fvs3 (vscade + IDF)
Introduction to ROS learning notes (II)
Esp32 (UART ecoh) - serial port echo worm learning (2)
使用晨曦记账本,分析某个时间段每个账户收支结余
listener.log
随机推荐
listener.log
Machine learning theory (7): kernel function kernels -- a way to help SVM realize nonlinear decision boundary
SSDB基础3
SQL中函数 decode()与 replace()的用法
RPM package management
使用晨曦记账本,分析某个时间段每个账户收支结余
std::stoi stol stoul stoll stof stod
【C语言进阶11——字符和字符串函数及其模拟实现(2))】
Loop path
程序员如何快速开发高质量的代码?
视频边框背景如何虚化,简单操作几步实现
Eight bit binary multiplier VHDL
Deeply understand what new and make in golang are and what are the differences?
Go 语言 GUI 框架 fyne 中文乱码或者不显示的问题
Implementation of TCP UDP communication with golang language
Using Visual Studio code to develop Arduino
Nacos cluster construction and MySQL persistence configuration
Esp32 drive encoder -- siq-02fvs3 (vscade + IDF)
Esp32 (UART 485 communication) - 485 communication of serial port (3)
电路在线模拟