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

This commit is contained in:
2026-07-19 15:15:59 +08:00
parent 8476e4095e
commit 5ff73a08ad
2 changed files with 64 additions and 0 deletions
@@ -0,0 +1,19 @@
package com.inmind.private02;
/*
构造方法的使用
*/
public class Demo04 {
public static void main(String[] args) {
//无参构造方法,创建学生对象
Student s1 = new Student();
s1.study("python");
//满参构造方法,创建学生对象
Student s2 = new Student("张三",18,1);
s2.study("java");
//第一天报名只知道学号
Student s3 = new Student(43);
System.out.println(s3.getId());
s3.study("C++");
}
}