Classes in Java are mainly divided into ordinary classes and system classes. Ordinary classes are user-defined, including concrete classes, abstract classes and final classes; system classes are provided by the Java standard library, including predefined classes and internal classes. Ordinary classes are used to encapsulate specific functions and data, abstract classes define public interfaces and abstract methods, the final class implements unchangeable state or behavior, internal classes access members of external classes, and system classes provide core functionality.
Class types in Java
Classes in Java can be roughly divided into two categories:
1. Common class
- ##User-Defined Class: A class created by developers to encapsulate data and Behavior.
- Concrete Class: A class that can be instantiated.
- Abstract Class: A class that cannot be instantiated can only be used as a base class for other classes to inherit.
- Final Class: A class that cannot be inherited.
2. System class
- Predefined Class: Class provided by the Java standard library, For example String
,
Integer, and
ArrayList.
- Internal Class (internal class): A class defined inside another class can use members of the external class.
The purpose of each class type
- Common classes: Used to encapsulate specific functions and data of the application.
- Abstract class: Define public interfaces and abstract methods for other classes to inherit and implement.
- Final class: Used to implement unchangeable state or behavior.
- Inner class: Access members of the outer class, such as for callbacks or implementing nested structures.
- System Classes: Provide core functionality and utilities without requiring developers to create their own classes.
The above is the detailed content of How many classes are there in java. For more information, please follow other related articles on the PHP Chinese website!