Java object-oriented Chapter I.

Source: Internet
Author: User

1. How to describe a design using class diagrams

-Private Property

+ Public (Common) method

Access modifiers:

Default (default), can only be accessed by classes in the same package

Private, access is minimal and can only be accessed on its own

Public, access is the largest and any class can access

Protected (Protected) "Inheritance explained"

2. Object-oriented design steps

A) Discovery Class (noun)

b) found attribute (noun or adjective)

c) Discovery method (verb)

3. concepts of classes and objects

L this keyword, which represents the object of the current class

n can only be used in the current class

n cannot appear in the static method

The method or property of the static tag that represents the member of the class

N in the current class, write the method name directly to invoke the

n is called in other classes

You must use the class name (or object name). Static member name "

L final keyword, which represents the constant of the class (stored unchanged data)

N-Modified global variables (attributes), constants

n constant names, followed by coding specifications, must all be capitalized

n declaration, you must assign a value immediately, you cannot modify the value of a constant in the following code

n How are constants called?

You write the constant name directly inside yourself

U in other classes, through "object name. Constant Name"

4. Constructors--1 special methods

A) characteristics?

I. Method name and class name are the same

II. No return type, void keyword No

III. In general, access modifiers are public

b) role?

Initializing a member of a class

c) How to invoke?

Automatically call construction methods when creating objects

Class Name Object name =new class name ("value");

How do the 2 constructor methods call each other after the method overload is constructed?

This ("value");//must be written in the first line

d) Precautions:

I. If there is no write construction method in the class, the system automatically provides a parameterless constructor to initialize the members of the class

Ii. if a constructor with parameters is written in the class, the system will no longer automatically provide a parameterless construction method

5. Method overloading

A) features

I. In the same class

II. Method names are the same

Iii. parameter list (number, type) is different

b) Precautions:

The access modifier has no relation to the return type of the method

2. How to invoke the overloaded method?

Automatically find the corresponding method based on the number and type of arguments passed

6. What are the benefits of encapsulation?

Hide implementation details to improve reusability and maintainability of the program

7, the package steps?

L Modify the public or default permissions of a property to private

L 2 Methods for writing encapsulation properties

n public void Set property name (attribute data type parameter name) {

}

n the data type of the public Property Get property name () {

return property name;

}

L Modify the Setter method body, write logical control statements (such as if), limit the values of parameters that do not conform to logic

1. Getter and setter methods for auto-generated attributes

L shortcut key: Shift +alt+ S+r

L myeclipse in the menu bar

Scource-->generate Getters and Setters ...

Java object-oriented Chapter I.

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.