您的位置:首页 > 其它

文章标题

2016-04-14 20:31 323 查看
person类的继承(student类)以及成员函数getInfo函数的重写。

package com.第三章lab;

class person1{

public String name;

public int age;

public person1(String name,int age){

this.name=name;

this.age=age;

}

public person1(){

}
public void getInfo(){
System.out.println(name);
System.out.println(age);
}


}

class Student extends person1{

public String school;

public Student (String name,int age,String school){

super.name=name;

super.age=age;

this.school=school;

}

public Student(){

}
public void Study(){
System.out.println(name+" is studing!");
}
public void getInfo(){
super.getInfo();
System.out.println(school);
}


}

public class person{

public static void main(String[] args){

Student s1=new Student();

s1.name=”lxp”;

s1.age=3;

s1.school=”JXNU”;

s1.Study();

s1.getInfo();

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: