类与对象

来源:互联网 发布:ubuntu重启网卡 编辑:程序博客网 时间:2024/06/06 15:02
package students;


 public class Student {
String Name;
String Address;
String Degree_name;
String Department;
int Year_Commenced;
static int STUDENT_ID_BASE=901000;
static int nextID=0;
int studentID;

String getName()

return Name;
}

String getAddress()

return Address;
}

String getDegree_name()

return Degree_name;
}

int getYear_Commenced()
{
return Year_Commenced;

}

public void setName(String Name)
{
this.Name=Name;

}

public void setAddress(String address)
{
this.Address=address;

}
public void setDegree_name(String Degree_name)
{
this.Degree_name=Degree_name;

}
public void setDepartment(String Department)
{
this.Department=Department;

}
public void setYear_Commenced(int Year_Commenced)
{
this.Year_Commenced=Year_Commenced;

}
public String toString()
{
return "Name: "+this.Name+" Department:"+this.Department+"Year Commenced:"+this.Year_Commenced+studentID;
}
//initial student

public Student()
{
this.Name="wang";
this.Address="Caberra";
this.Degree_name="computer";
this.Department="anu";
this.Year_Commenced=2016;

}

public Student(String name)
{   this();
this.Name=name;
this.nextID=this.nextID+1;
this.studentID=this.STUDENT_ID_BASE+this.nextID;
}

public Student(String name, String address)
{
this();
this.Address=address;
this.Name=name;
this.nextID=this.nextID+1;
this.studentID=this.STUDENT_ID_BASE+this.nextID;
   }

public Student(String name, String address, String department)
  {
this();
this.Name=name;
this.Department=department;
this.Address=address;

this.nextID=this.nextID+1;
this.studentID=this.STUDENT_ID_BASE+this.nextID;
  }

public static void main(String[] args) 
  { 
Student m = new Student("wangzhifeng", "22", "anu");
Student n= new Student("wangzhifng");
Student j= new Student("wangzhifen", "unsw");
Student mm = new Student("wangzhifeng", "anu", "au");

   System.out.println(m.toString());  
   System.out.println(n.toString()); 
   System.out.println(j.toString());  
   System.out.println(mm.toString()); 
   }  

}


   
0 0
原创粉丝点击