Home > Java > Javagetting Started > body text

What does class mean in java

(*-*)浩
Release: 2019-11-09 10:58:23
Original
14285 people have browsed it

Class (Class) is the basis for information encapsulation in object-oriented programming (OOP, Object-Oriented Programming). A class is a user-defined reference data type, also called a class type. Each class contains a data description and a set of functions that manipulate data or pass messages. Instances of a class are called objects.

What does class mean in java

Class is a concept in object-oriented language programming and the basis of object-oriented programming. Classes can be thought of as templates for creating Java objects. (Recommended learning: java course )

The essence of the class is a reference data type, similar to byte, short, int (char), long, float, double and other basic Data type, the difference is that it is a complex data type. Because its essence is a data type, not data, it does not exist in memory and cannot be directly manipulated. It only becomes operable when it is instantiated as an object.

A class is an abstraction of a class of things with common characteristics in real life. If the data types provided in a program directly correspond to the concepts in the application, the program will be easier to understand and easier to modify.

A well-chosen set of user-defined classes will make your program cleaner. Additionally, it makes various forms of code analysis easier to perform. In particular, it would also make it possible for the compiler to check for illegal uses of objects.

The class encapsulates properties and methods internally, which are used to operate its own members. A class is the definition of a certain object and has behavior. It describes what an object can do and the methods (methods) used to do it. They are programs and processes that can operate on this object. It contains information about how an object behaves, including its name, properties, methods, and events.

The composition of a class includes member attributes and member methods (data members and member functions).

Data members correspond to the attributes of the class. The data members of the class are also a data type and do not require memory allocation. Member functions are used to operate various attributes of the class, which are unique operations of a class. For example, "students" can "take classes", but "fruit" cannot. The interaction between a class and the outside world is called an interface.

Three major characteristics of classes

Encapsulation

encapsulates data and operations into an organic whole. Because classes The private members are hidden and only provide limited interfaces to the outside, so it can ensure high internal cohesion and low coupling with the outside. Users do not need to know the specific implementation details, but only need to use the members of the class with specific access rights through the external interface, which can enhance security and simplify programming.

Inheritance

Inheritance is more in line with cognitive rules, making the program easier to understand while saving unnecessary duplication of code.

Polymorphism

The same operation acts on different objects, and can have different interpretations and produce different execution results. At runtime, methods in the implemented subclass (derived class) can be called through a pointer to the parent class (base class).

The above is the detailed content of What does class mean in java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template