Basic object-oriented knowledge and basic object-oriented knowledge

Source: Internet
Author: User

Basic object-oriented knowledge and basic object-oriented knowledge

Object-oriented concepts

: It refers to thinking about problems in the form of objects. When abstracting objects, the value cares about the points we pay attention to and ignores the points we don't pay attention.

There are two very important elements in Object-Oriented Systems: Class and object)

Class: A class is an abstract concept and a wide range of values.

Object: specific individual

The element (person) in the class: attribute: Describes the inherent property method of a class of things: describes the action of things.

A class is an abstract concept that contains data (attributes) and Action (placement) of an operation class. An object is a specific expression of a class, at the same time, the object also has attributes and methods,

Data-attribute: Also known as a member variable. all nouns in a class are data.

Action of operating data-method: All verbs in the class are methods

Object-oriented four/three features:

Abstraction, encapsulation, inheritance, and Polymorphism

Abstract: extract the attributes and methods that we care about in a collection, and ignore those that we don't care about.

Encapsulation: encapsulate abstract Tao attributes and methods into a class.

Write a class to encapsulate the format

Access modifier Class Name

{

// Attributes

// Method

}

Inherent format of writing methods

Access modifier return value type method name (parameter...) {// method body}

Return Value: return;

Call method:

1. Create an object: class name variable name = new Class Name ();

2. Call method: variable name. Method Name (parameter );

Main is the entry for executing a program. A program can only have one main method. If there is no main method, the program cannot be executed.

Notes for writing methods:

1. The method cannot be nested, and the method cannot define another method.

2. the return value type of the method must be the same as the return value type of the method. Otherwise, an error is returned.

3. methods must be declared before they can be called.

4. void indicates no return value

5. return is used to return data. It is generally written in the last row of the method.

6. If the current method does not need to be returned, you can use return to prevent the program from running.

Format parameters and actual parameters:

Form parameter:-when defining a function, the variable name in the brackets following the function name is a form parameter or a form parameter.

Actual parameters:-when a function is called, the variable name in the brackets following the function name is called an actual parameter or a real parameter.

Member variables (attributes ):

Access modifier variable type variable name [= initial value]

Call member variables:

Variable name. attribute name

Differences between member variables and local variables: Partial Variables are written in the method, and member variables are written out of the method.

Classification of variables:

Variables of the basic data type: int a; double B;

Person p = new Person ();

Constructor

How to create an object:

Access modifier Class Name (parameter list)

{// The return value may not be returned if the method is tired}

Note:

(1). The method name and class name must be consistent.

(2). constructor does not return values.

(3). the constructor is called by the Java Virtual Machine when an object is created, instead of manually calling the constructor.

(4) If a class is not defined, jvm will add a construction method without parameters to the class during compilation.

(5). If you define a constructor yourself, jvm will not create a constructor without parameters. In this case, you need to define a construction method without parameters.

Method overloading:

1. Methods in java can be renamed. We call this method a method overload.

2. Precautions for using method overloading:

(1). Method overloading can be called only when the method name is the same

(2). Any method can implement method overloading.

(3) ensure that the order or number of parameters in the parameter list is different.

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.