当前位置:网站首页>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
边栏推荐
- Use of content provider
- Accessing private members using templates
- os_authent_prefix
- Sentinel service fusing practice (sentinel integration ribbon + openfeign + fallback)
- 使用晨曦记账本,分析某个时间段每个账户收支结余
- 12 examples to consolidate promise Foundation
- iptables -L执行缓慢
- [mathematical modeling] - analytic hierarchy process (AHP)
- Recyclerview control list item layout match_ Fundamental principle of parent attribute invalidation
- Download xshell 6 and xftp6 official websites
猜你喜欢
ESP32 LVGL8. 1 - checkbox (checkbox 23)
Solutions such as unknown or garbled code or certificate problem prompt in Charles's mobile phone packet capture, actual measurement.
C: generic reflection
Iptables - L executes slowly
Simplified path (force buckle 71)
Using Visual Studio code to develop Arduino
os_ authent_ Prefix
iptables -L执行缓慢
Sword finger offer II 116 Number of provinces - spatial complexity O (n), time complexity O (n)
How to virtualize the video frame and background is realized in a few simple steps
随机推荐
How can programmers quickly develop high-quality code?
ctfshow-web362(SSTI)
Actual combat of Nacos as service configuration center
How about CICC wealth? Is it safe to open an account up there
特征选择feature_selection--SelectKBest
Druid SQL和Security在美团点评的实践
[mathematical modeling] - analytic hierarchy process (AHP)
mysql_ Download and installation of Linux version
【科普】CRC校验(一)什么是CRC校验?
Using bafayun to control the computer
K210 serial communication
Getting started with vcpkg
Introduction to ROS learning notes (II)
One of the reasons why the WebView web page cannot be opened (and some WebView problem records encountered by myself)
Machine learning practice - naive Bayes
C: generic reflection
Click the input box to pop up the keyboard layout and move up
On iptables
From technical system to business insight, the closing chapter of the practice of small and medium-sized R & D team structure
使用晨曦记账本,分析某个时间段每个账户收支结余