In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "the principle and usage example analysis of Java local inner class". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor to take you to learn the "Java local internal class principle and usage example analysis"!
A little bit of eye contact
If an inner class is defined in a method, then the inner class is a local inner class, and the local inner class is valid only in the method.
Because the local inner class cannot be used outside the methods of the outer class, the local inner class cannot be modified with the control conformance static modifier.
If you need to define a variable, create an instance, or derive a subclass with a local inner class, it can only be done in the same method as the local inner class.
Two code
Public class LocalInnerClass {public static void main (String [] args) {/ / define the local inner class class InnerBase {int a;} / define the local inner class subclass class InnerSub extends InnerBase {int b;} / / create an object of the local inner class InnerSub is = new InnerSub (); is.a = 5; is.b = 8; System.out.println ("the an and b instance variables of the InnerSub object are:" + is.a + "," + is.b);}} "
Three operation
The an and b instance variables of the InnerSub object are: 5pm 8
Four instructions
After compilation, three files, LocalInnerClass.class, LocalInnerClass$1InnerBase.class, and LocalInnerClass$1InnerSub.class, are generated. The reason why the local inner class has numbers is that there may be more than two local internals of the same name (in different methods) in the same class.
The local internal scope is too small to facilitate multiple reuse, so local internal classes are rarely used in development.
At this point, I believe that everyone has a deeper understanding of the "Java local internal class principle and usage example analysis", might as well come to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.