Java:创建继承于类Person的类Student并重写方法

  • Post author:
  • Post category:java


class Person{

String name;

String sex;

int age;

void getInfo(String n,String s,int a)

{

name=n;

sex=s;

age=a;

}

void showInfo()

{

System.out.println(“姓名:”+name);

System.out.println(“性别:”+sex);

System.out.println(“年龄:”+age);

}

}

public class Student extends Person {

String id;

String school;

void setInfo(String num,String school_name)

{

id=num;

school=school_name;

}

void showInfo()

{

System.out.println(“学校:”+school);

System.out.println(“学号:”+id);

System.out.println(“姓名:”+name);

System.out.println(“性别:”+sex);

System.out.println(“年龄:”+age);

}

public static void main (String[] args) {

// TODO 自动生成的方法存根

System.out.println(“第一个人的信息”);

Student z=new Student();



版权声明:本文为YanXiaoJu17原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。