Java object-oriented: object-oriented thinking and overview

Source: Internet
Author: User

1: Object oriented thinking

Object-oriented is a process-oriented programming idea.

Process oriented: Emphasis on the steps of each of these functions

Object-oriented: emphasizes the object and then invokes the function by the object

2: Object-oriented thinking features

A: It's a thought that's more in line with our thinking habits.

B: complex things can be simplified

C: turning us from the executor to the conductor

Development, design, features

Object Oriented development

is to constantly create objects, use objects, and command objects to do things.

Object-oriented design

is to manage and maintain the relationship between objects.

Object-oriented features

Package (encapsulation)

Inheritance (inheritance)

polymorphic (polymorphism)

Overview of Classes and objects:

How do you describe a thing in the real world ?

Example: Student

name , age , gender ...

study , eat , sleep

Properties: Descriptive information about the thing

Behavior: What the thing can do

We learn programming languages in order to simulate things in the real world.

and the programming language we learn The most basic unit in Java is: class.

So, we should put things through the class to reflect:

In this way, we get the correspondence between the real world things and the classes:

things: class:

Properties member Variables

Behavior member Methods

Class: is a set of related properties and behaviors. is an abstract concept.

Object: Is the concrete manifestation of this kind of thing. Specific existence of the individual.

Example:

Student: Class

Monitor: Object

Demo

Class Student {

Defining Variables

name

String name;

Age

int age;

Address

String address;

Defining Methods

How to learn

public void Study () {

SYSTEM.OUT.PRINTLN (" Students Love Learning ");

}

the way to eat

public void Eat () {

System.out.println (" learn to be hungry, to eat ");

}

the way to sleep

public void sleep () {

System.out.println (" Learning tired , to Sleep ");

}

}

Write two classes in a java file: A basic class, a test class.

Note: The file name matches the test class name.

How to use it ?

Create objects to use.

How do I create an object ?

format: Class Name Object name = new class name ();

How do I use member variables ?

The name of the object . Variable name

How do I use member methods ?

The name of the object . Method Name (...)

Memory diagram of an object:

Memory graph of two objects:

Memory graphs for three objects:

 

Java Object-oriented: object-oriented thinking and overview

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.