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

Object-oriented case Analysis in Java

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

Most people do not understand the knowledge points of this "object-oriented case analysis in Java" article, so the editor summarizes the following contents, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "object-oriented case analysis in Java" article.

I. brief introduction

There are two important points of knowledge in Java:

Process-oriented: at that time to achieve a function, each specific step needs to be comprehensive, deal with every detail in detail. To make an analogy: when you are in the exam, you need to write each question yourself. Focus on the whole process.

Object-oriented: when you need to implement a function, you don't care about the specific steps, just find an object with that function to implement it. Make an analogy: this is like the teacher gives out a paper, this paper can be written by you, or he can write, as long as you can finish it. [focus on the object that completes this function].

Object-oriented programming (Object Oriented Programming,OOP): organizing code as classes and organizing (encapsulating) data as objects.

Classes and objects are very similar, so what is the difference between them? What does it matter?

The difference and relationship between classes and objects:

1. A class is a description of a class of things, which is abstract; an object is an instance of a class of things, which is concrete.

2. The class is the template of the object, and the object is the entity of the class.

Second, the use of objects

To create an object, you usually create an object through the new keyword.

Class name object name = new class name ()

Use methods and variables in the object.

Object name. Member method (): object name. Member variable

Examples of the use of objects.

Corresponding to the class of Java: member variable (attribute): String name; / / name int age; / / Age member method (behavior): public void eat () {} / / eating public void sleep () {} / / sleeping public void study () {} / / Learning Note: 1. Member variables are defined directly in the class, outside the method. two。 Member methods do not write the static keyword. * / public class Student {/ / member variable String name; / / name int age; / / name / / member method public void eat () {System.out.println ("eat!") ;} public void sleep () {System.out.println ("sleep!") ;} public void study () {System.out.println ("learn!") The difference between member variables and local variables

(1) the position in the class is different. Member variables are in the class, outside the method; local variables are in the method or on the method declaration (parameters).

(2) the scope of action is different. Member variables act in the class; local variables act in the method.

(3) initial values are different. Member variables have default values; local variables must be defined, assigned, and finally used.

(4) the location in memory is different. Member variables are in heap memory; local variables are in stack memory.

(5) the life cycle is different. Member variables exist as the object is created and disappear as the object is created; local variables disappear as the method is called.

The above is about the content of this article on "object-oriented case Analysis in Java". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more related knowledge, please pay attention to the industry information channel.

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