定义类并应用

来源:互联网 发布:算法对程序员的重要性 编辑:程序博客网 时间:2024/05/16 06:00

//StudentTest.java

class Student{
 String name;
 String telphone;
 Student(String a,String b){
  name=a;telphone=b;
 }
 void showMessage(){
  System.out.print(" "+name+":");
  System.out.println(""+telphone+"/n"); 
 }
}
class StudentTest{
 public static void main(String[] args){
  Student stuA=new Student("jingle","13525166785");
  System.out.println("StudentA's information:");
  stuA.showMessage();
  Student stuB=new Student("MeiFei","13525135004");
  System.out.println("StudentB's information:");
  stuB.showMessage();
 }
}

原创粉丝点击