JAVA SE basic feed --04: classes and objects, encapsulation

0x01. Classes and Objects

Object-oriented three features:

Encapsulation

Succession

Polymorphism

Related concepts:

Class : is a group of related properties and behavior of the collection.

Object : a class is a concrete manifestation of things.

The relationship between classes and objects :

Class 1 is a description of a class of things, abstract.

2. The object is an instance of a class of things, is specific.

Class definition:

Definition Format:

public class Name{
    //成员变量
    //成员方法
}

Member variable: that ordinary variables.

Member method: that is the ordinary method.

Objects of Use:

Using the format:

类名 对象名=new 类名();

Use variables and methods of class Object Access:

对象名.成员变量
对象名.成员方法

Member variable initial value will be defined as follows:

 Member variables and local variables:

 0x02. Package

The principle of encapsulation: the hidden attribute, if the need to access the property, providing a common approach to deal with.

private keyword:

meaning:

1.private within the competence modifier, representing the minimum permissions.

2. The member variables and member methods can be modified.

3. be modified private member variables and member methods, it can only be accessed in this class.

Using the format:

private 变量类型 变量名

Access a private member variable modified by a proprietary method getXxx, setXxx. May be generated by code generation function.

this keyword:

Meaning: access classes where representatives, who call the method, this on behalf of anyone.

Using the format:

this.成员变量

Construction method:

Meaning: When an object is created, the constructor for the object to the member variable assignment.

All classes have a constructor, if I did not write, in fact, Java is also provided.

Using the format:

修饰符 构造方法名(常用类名代替) (参数列表){
    ......
}

Constructor can be overloaded and can not contain the parameter, the parameters may be contained.

JavaBean:

JavaBean is writing code in a Java language specification.

In line with the standard JavaBean class should:

1. All member variables modified by private.

2. Each member variable is set to a getXxx, setXxx method for accessing member variables.

3 contains a non-argument constructor suggested comprising a constructor parameter.

as follows:

public class person {
    private String name;

    public person() {
    }

    public person(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

0x03.API

Meaning: API (Application Programming Interface), an application programming interface.

JDK provides a description of Jaca API documentation.

JDK1.6 official Chinese version, there is no follow-up.

可以查看一些类的包名,只有 java.lang下的类不需要导包。

 

 

此章结束。

发布了19 篇原创文章 · 获赞 7 · 访问量 424

Guess you like

Origin blog.csdn.net/ATFWUS/article/details/104267911