亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Home Java JavaBase what is java class

what is java class

Nov 09, 2019 am 11:01 AM
java class

what is java class

#What is a java class?

Java/Classes and Objects

Java is an object-oriented programming language. In addition to basic data types, Java requires that every data type must is a class.

The object-oriented programming idea strives to make the description of things in computer language as consistent as possible with the original appearance of the thing in the real world. Classes and objects are the core of object-oriented methods. concept.

A class is a description of a certain type of thing, which is an abstract and conceptual definition; the object is an individual of the type of thing that actually exists, so it is also called an instance. The relationship between classes and objects is like the relationship between concepts and objects. A class is like a template, and an object is an instance of the template.

The main idea of ??object-oriented is to regard objective things as objects with states and behaviors, and find out the common states and behaviors of the same type of objects through abstraction to form a class.

Class declarations in Java all begin with class.

class 類名稱 {
//聲明成員變量
//聲明成員方法
}

Construction method

In a Java program, the main job done by the construction method is to help newly created objects assign initial values. The constructor method can be regarded as a special method. Its definition is similar to that of ordinary methods. Its syntax is as follows:

Definition method of constructor

class 類名稱 {
訪問(wèn)權(quán)限 構(gòu)造方法名稱(){
}
}

When using the constructor Please note the following points:

It has the same name as the class name

It has no return value

The calling timing of the constructor method is also different from the general method. The general method is called when needed, while the constructor method is automatically called when the object is created, and the contents of the constructor method are executed. Therefore, the constructor does not need to be called directly in the program, but is automatically executed when the object is created. Based on the characteristics of the above construction method, it can be used to initialize the data members of the object. The so-called initialization is to assign an initial value to the object.

Creating objects

Generation of objects

Creating an object belonging to a certain class requires two steps:

Declare variables pointing to "objects created by classes"

Use new to create new objects and assign them to previously created variables.

Class name object name = new class name();

For example, if you want to create an object of the Person class, you can use the following statement to achieve it:

Person p ; // 先聲明一個(gè) Person 類的對(duì)象 p
p = new Person() ; // 用 new 關(guān)鍵字實(shí)例化 Person 的對(duì)象 p

Access A variable or method in the object

Access attribute: object name.Attribute name

Access method: object name.Method name()

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

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

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1488
72