A Java class is a collection of entities with certain common characteristics. It is an abstract data type, which is an abstraction of entities with the same characteristics. In object-oriented programming languages, a class is an abstraction of the properties and behavior of a type of "thing".
Give an example to illustrate the following class. For example, Person (person) is a class , then a specific person "Zhang San" is Objects of the "human" class, and information such as "name, height, weight" are the attributes of the object, and human actions such as "eating, dressing" are the methods of the object. (Recommended learning: java course)
In short, a class is a collection of things with the same characteristics, and an object is a specific instance of a class. Simultaneous classes have polymorphism and inheritance. For example, "human beings" can be divided into "men, women", "elderly people, children", then "men, women" are subclasses of "human beings" and so on.
The definition of class Person in Java language is often as follows:
public class Person { private String name; //属性:姓名 private int height; //属性:身高 private int weight; //属性:体重 public Person() {} public Person(String name, int height, int weight) { this.name = name; this.height = height; this.weight = weight; } //... some methods... public void doSth() { //行为: //... do something }}
A class can be regarded as a template for creating Java objects.
A class can contain the following types of variables:
Local variables: Variables defined in methods, constructors, or statement blocks are called local variables. Variable declaration and initialization are all in methods. After the method ends, the variables will be automatically destroyed.
Member variables: Member variables are variables defined in the class and outside the method body. Such variables are instantiated when the object is created. Member variables can be accessed by methods, constructors, and statement blocks of a specific class.
Class variables: Class variables are also declared in the class, outside the method body, but they must be declared as static type.
A class can have multiple methods. In the above example: barking(), hungry() and sleeping() are all methods of the Dog class.
The above is the detailed content of What does java class mean?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Dreamweaver CS6
Visual web development tools