构造方法(初学)

package day01;

public class Student {
private String name;
private int age;

public Student() {
System.out.println("无参构造");
}

public Student(String name,int age) {
System.out.println("有参构造");
this.age = age;
this.name=name;
nihao();
}

public String getName() {
return name;
}

public int getAge() {
return age;
}

public void setName(String name) {
this.name = name;
}

public void setAge(int age) {
this.age = age;
}
public void hi(String name,int age){
System.out.println("我叫"+name+"今年"+age);
System.out.println("我叫"+this.name+"今年"+this.age);
}
public void nihao(){
System.out.println("我叫"+this.name+"今年"+this.age);
}
}

package day01;
//import day01.Student
public class Case03 {
public static void main(String[] args) {
Student stu1=new Student();
Student stu2=new Student("Lucken",18);

}
}
posted @ 2019-04-08 13:57  py-clj  阅读(158)  评论(0编辑  收藏  举报