Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the principle of java classes and objects

Shulou Source: shulou.com Published: 2022-06-02 18:12:05 10月22日 Update

This article mainly explains "what is the principle of java classes and objects". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what is the principle of java classes and objects"?

Object-oriented programming OOP

Class: a collection of similar objects.

Object

Object: solid. Everything that can be described.

Attribute: feature.

Methods: action, behavior.

The difference between classes and objects

[1] the class is abstract and the object is concrete.

[2] A class is a template that creates objects with common properties and methods.

[3] Class is a kind of data intensity. Reference data type.

Grammar

The public classs class name {/ / defines the type attribute 1 of attribute 1; the type attribute 2 of attribute 2. Type attribute n of attribute 3; / / define method part method 1; method 2;. Method m;}

Naming convention for class names

Named after Pascal. It is made up of multiple words, with the first letter of each word capitalized.

Definition method

Grammar

The access modifier returns the value type method name (parameter 1, parameter 2. Parameter n) {method body;}

Method with return value

Note:

[1] must have a return value; return a value

[2] the type must match

[3] cannot return more than one value, only one value

The function of the method

Encapsulation and reuse of code.

Define CLA

Multiple classes can be defined in a file, but only one class is public. It is usually agreed that the class with the main method is public, and the class name modified by public must be the same as the file name.

The difference between member variables and local variables

Local variable: defined in a method or code block. Member variable: defined in the class. 1. Initial value. The local variable system does not initialize and needs to initialize itself. The member variable system initializes automatically according to the type. two。 Scope. A local variable can only be used in the code block or method that defines it. Member variables are valid throughout the class. 3. Priority. The member variable has the same name as the local variable, the local variable is preferred, and the member variable is hidden.

This

Represents an object of this class

Function: used to distinguish between member variables and local variables. Function 2: call the construction of this class.

At this point, I believe you have a deeper understanding of "what is the principle of java classes and objects". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Methods variables objects attributes local members types functions principles code parameters multiple class names contents words blocks data files systems syntax Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Shulou Tech Info MariaDB Apple OPPO Reno