11.13 Daily

Summary of the definition format of the
class public class class name { // Declare an attribute without assignment type name attribute name; // declare while assign value type name attribute name = attribute value;



// 基本方法的定义
public void 方法名1() {
    编写方法1所需要执行的各种代码;
}

// 具有返回值的方法
public 返回值类型 方法名2() {
    编写方法2所需执行的代码;
    return 返回值;
}

// 具有参数的方法
public void 方法名3(形参的类型 形参名称,形参的类型n 形参名称n) {
    编写方法3所需执行的代码;
}

// 具有参数,且具有返回值的方法
public 返回值类型 方法名4(形参的类型 形参名称,形参的类型n 形参名称n) {
    编写方法4所需执行的代码;
    return 返回值;
}

}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Summary of object usage format
public class test { public static void main(String[] args) { // Instantiate the class into an object class name object name = new class name();


    // 对象的属性值获取
    System.out.println(对象.属性名);

    // 修改对象的属性值
    对象.属性名称 = 值;

    // 调用对象的方法
    对象名.方法1名();

    // 调用具有返回值的方法
    返回值类型 变量名称 = 对象名.方法2();

    // 调用带有参数的方法
    对象.方法名3(实参1,实参n);

    // 即有参数,又有返回值的方法调用
    返回值类型 变量名 = 对象.方法名4(实参1,实参n);
}

}

Guess you like

Origin blog.csdn.net/zzxin1216/article/details/109686570