Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the principle of java classes and objects

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report