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

Source: Internet
Author: User

Internal class
Class within the class
1. Solve multiple inheritance
2. resolves conflicts between methods during inheritance and interface implementation
3. Data Hiding
 
Only internal classes can have four types of access Modifiers
When the internal class is private, an external class provides methods to access the internal class.
 

Regular internal class
1. Static attributes and methods are not allowed
2. Internal classes can use all attributes and methods of external classes.
3. External classes cannot directly use internal class attributes and methods. They must be instantiated before use.
 
If the attributes and methods of the internal class mask the external class methods
External class. this. Attributes/methods
To call the attributes and methods of an external class.
 
Static internal class
It can contain static methods and attributes.
No need to instantiate external classes
StaticOutter. StaticInner in =
New StaticOutter. StaticInner ();
 
Local internal class
Internal class inside the Method
1. access modifier www.2cto.com is not available
2. 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 within the local internal class.
 

Anonymous internal class
Callback method, internal class without class name
1. There is only one non-argument constructor In the subclass.
2. The instance must be instantiated immediately.
 
Abstract class
Classes declared in abstract form
As long as a class contains an abstract method, this class must be a cabling class.
Abstract classes do not necessarily contain abstract methods.
Abstract classes can inherit abstract classes. All abstract methods are implemented by the first non-Abstract subclass.
 
Abstract method, implemented by the first non-Abstract subclass
As long as there is an abstract method, the class must be an abstract class
Abstract classes do not necessarily contain abstract methods.
Cannot abstract attributes
Abstract methods cannot be declared as private or final methods.

 
Interface:
Java multi-Inheritance
An interface is a description of a set of requirements, instead of a class.
100% Abstraction
All methods are abstract methods.
 
All methods are abstract by default, so you do not need to mark the method as abstract
All variables are static final variables by default.
 

Implements: Implementation Interface
Class A implements Interface
Interface inheritance interface, which can implement multi-Inheritance
Interface B
Interface C
Interface A extends B, C

 

Related Article

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.