Java Object-oriented

Source: Internet
Author: User

What is object-oriented?

Process-oriented and object-oriented is a way of thinking in our programming, writing programs.

The process-oriented programming approach is the process of thinking "What should I do" when encountering one thing, and then step-by-step implementation.

For example: Company cleaning (wipe glass, sweeping, mopping, garbage, etc.), in accordance with the process-oriented programming approach will think "cleaning how I do, and then a piece of the completion", finally the company clean up the health.

L Object-oriented programming, is to meet one thing, think "I should let who do", and then that "who" is the object, how he will do this thing is his own thing, anyway, the last group of objects together can be good on the line.

For example, the company to clean (wipe glass, sweeping, mopping, garbage, etc.), in accordance with the object-oriented programming approach will think , "I should let who do, such as Xiao Ming wipe glass, Jean Xiaoli sweep, let Xiao Guo drag the ground, let the cockroach trash, etc.", Here "Xiao Ming, Xiao Li, Xiao Guo, Xiao Qiang "is the object, they want to clean, how to clean their own business, anyway, the last group of objects together to clean up the company's health

Build Wheels

The object is reflected in the code:

L define the format of the class

public class class name {

you can write 0 to n Properties

Data Type variable name 1;

Data Type variable name 2;

you can write 0 to n methods

modifier return value type Method Name ( parameter ) {

execute the statement ;

}

}

Such as:

L Auto Class

public class Car {

String color;

int number;

void Run () {

System. out. println (color + ":" + number);

The real meaning of the class is to describe things. Attributes and functions are collectively referred to as members of a thing.

The members of a thing are divided into two types: member properties and member functions.

Member properties are reflected in the code as member variables

Member functionality is reflected in the code as a member method

To create the format of an object:

Class name New name = Class name ()

Differences between classes and objects:

The object-oriented programming idea tries to keep the description of things in the program consistent with the shape of the things in reality. In order to do this, the object-oriented idea presents two concepts, namely, classes and objects. Where a class is an abstract description of something, and the object is used to represent the individual of that kind of thing in reality.

What is the difference between a local variable and a member variable?

Difference One: the location of the definition is different

Variables defined in a class are member variables

defined in the method or the variable inside the {} statement is a local variable

Difference two: The location in memory is different

Member variables are stored in the object of the heap memory

Local variables are stored in the stack memory method

Difference three: The declaration period is different

Member variables appear in the heap as the object appears and disappear from the heap as the object disappears

Local variables appear in the stack as the method runs, disappearing as the stack of methods pops up

Difference Four: Initialize different

Member variable because in heap memory, all default initialization values

Local variables do not have default initialization values and must be assigned manually before they can be used.

Java Object-oriented

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.