day06-封装的优化_构造方法
This commit is contained in:
@@ -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++");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user