当前位置:   article > 正文

设计一个person类java_定义一个Person类,含姓名、性别、年龄等字段;继承Person类设计...

设计一个java类 person,包含以下属性:姓名(name)、年龄(age)、性别(gender),属性

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

package test2;

public class Person {

int age;

String name;

String gender;

public Person(int Age,String Name,String Gender) {

this.age=Age;

this.name=Name;

this.gender=Gender;

}

public String toString() {

return "姓名:"+name+"性别:"+gender+"年龄:"+age;

}

public static class Teacher extends Person{

static String title;

static String department;

public Teacher(String Title,String Department) {

super(Age,Name,Gender);

this.title=Title;

this.department=Department;

}

public String toString() {

return "姓名:"+name+"性别:"+gender+"年龄:"+age+"职称:"+title+"部门:"+department;

}

public static class Student extends Person{

int num;

int time;

String professional;

public Student(int Num,int Time,String Professional) {

super(Age,Name,Gender);

num=Num;

time=Time;

professional=Professional;

}

public String toString() {

return "姓名:"+name+"性别:"+gender+"年龄:"+age+"职称:"+title+"部门:"+department+"学号:"+num+"入学时间:"+time+"专业:"+professional;

}

public static void main(String args[]) {

Person s1=new Person("千寻","女",18);

System.out.println(s1);

Person s2=new Person("小嗝嗝",男,19,"驯龙高手","技术");

System.out.println(s2);

Person s3=new Person("波妞",女,17,"编程","技术部门","2017007","2017","通信");

System.out.println(s3);

}

}

}

能否帮忙看一下,求指教

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/136537
推荐阅读
相关标签
  

闽ICP备14008679号