day06-面向对象-封装的优化_构造方法

This commit is contained in:
2026-01-19 11:58:42 +08:00
parent a1960a6a27
commit b9ec239980
2 changed files with 58 additions and 3 deletions

View File

@@ -9,7 +9,7 @@ package com.inmind.object01;
public class Demo04 {
public static void main(String[] args) {
//创建一个学生,并给学生设置属性值,展示该学生
Student s = new Student();
Student s = new Student("lisi");
System.out.println("s的地址"+s);//s中保存的是地址
//设置属性
//s.name = "张三";
@@ -19,6 +19,11 @@ public class Demo04 {
System.out.println(s.getName());
System.out.println(s.getAge());
s.show();
System.out.println("-------------");
//通过有参构造,创建学生对象
Student s1 = new Student("王五", 22);
s1.show();
s1.setName("王五1");
s1.show();
}
}