day06--封装的优化_构造方法

This commit is contained in:
2026-09-21 11:36:43 +08:00
parent 6476d75539
commit 1bfb1d88f7
2 changed files with 68 additions and 0 deletions
@@ -0,0 +1,15 @@
package com.inmind.constructor03;
public class Demo04 {
public static void main(String[] args) {
//创建学生
Student s = new Student();
System.out.println(s.name);
//直接创建学生并携带name属性
Student s1 = new Student("张三");
System.out.println(s1.name );
Student s2 = new Student("李四",18);
System.out.println(s2.name);
System.out.println(s2.age);
}
}