day06-面向对象的案例

This commit is contained in:
2026-07-19 15:45:37 +08:00
parent 74dfe4ade7
commit 1f97875bbc
2 changed files with 24 additions and 8 deletions
+8 -8
View File
@@ -25,12 +25,12 @@ public class Student {
}
//getter和setter方法
public int getId() {
return id;
public String getName() {
return name;
}
public void setId(int id) {
this.id = id;
public void setName(String name) {
this.name = name;
}
public int getAge() {
@@ -41,12 +41,12 @@ public class Student {
this.age = age;
}
public String getName() {
return name;
public int getId() {
return id;
}
public void setName(String name) {
this.name = name;
public void setId(int id) {
this.id = id;
}
//自定义的行为(成员方法)
+16
View File
@@ -0,0 +1,16 @@
package com.inmind.test04;
/*
* 最贵的书。
* 定义一个图书Book类。
- 属性:图书编号,书名,价格,出版日期
- 构造方法:
- 无参构造方法,满参构造方法
- 成员方法:
- get/set方法
- showBook方法,输出图书信息
* 定义测试类,使用满参构造方法,创建三(多)个Book对象,判断价格最贵的图书(存放书的数组的遍历),并输出图书信息。
*/
public class Test05 {
}