Java -- class and interface -- regular internal class, static internal class, local internal class, anonymous internal class

Source: Internet
Author: User

Internal class within the class 1. solve multi-inheritance 2. resolves method name conflicts during inheritance and interface implementation. 3. only internal classes can have four access modifiers. When internal classes are private, external classes provide methods to access internal classes. static attributes and methods are not allowed. internal classes can use all attributes and methods of external classes. 3. external classes cannot directly use internal class attributes and Methods. Before use, you must first instantiate the internal class attributes and methods to shield external class methods. this. attributes/methods to call external class attributes and Methods static internal classes can contain static methods and attributes and do not need to instantiate external class StaticOutter. staticInner in = new StaticOutter. staticInner (); the internal class of the local internal class within the method 1. no access modifier 2. you can access the local variables in the method and all attributes and methods in the class. 3. if there is a local variable in the local internal class blocking method, the local variable cannot be accessed in the local internal class. The anonymous internal class callback method does not have the class name. subclass has only one non-argument constructor 2. the abstract class must be instantiated immediately. A Class declared in abstract must contain an abstract method. This class must be a class that does not necessarily contain abstract methods. abstract classes can inherit abstract classes, all abstract methods are implemented by the first non-Abstract subclass. If the first non-Abstract subclass implements an abstract method, the class must be an abstract class. abstract classes do not necessarily contain abstract methods. abstract methods cannot be abstract properties. abstract methods cannot be declared as private or final method interfaces. interface: solve the problem that multiple inheritance interfaces in java are not classes, description of a set of requirements 100% abstract all methods are abstract methods by default, so you do not need to mark the method as abstract all variables as static final variables implements by default: implements the class A implements Interface interface inheritance interface, which can implement multiple inheritance interfaces B Interface C interface A extends B, C

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.