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