uiouoij 2021-04-07 22:00 采纳率: 0%
浏览 626

定义一个新的类Student类,继承Person 类。

定义一个新的类Student类,继承Person 类。要求:1)增加“school” 属性为String 类型。 2)重 载Student类的构造方法,Student(String n,String I,String school)。3) 重写Person类的info()方法,增加school信息。class Person{ private String name; private String location; Person(String name, String location){ this.name =name; this.location =location ; } public String info() { return "name:"+name+"location:"+location; } 

  • 写回答

1条回答 默认 最新

  • Bob_88888 2021-04-07 22:30
    关注
    package designpattern.csdn;
    
    /**
     * Author Bob
     * Date
     * Description
     **/
    public class Person {
    
        public String name;
    
        public String location;
    
        public Person(String name, String location){
            this.name = name;
            this.location = location;
        }
    
        public String info(){
            return "name:" + name + "location:" +location;
        }
    
        public Person(){
    
        }
    
    }
    package designpattern.csdn;
    
    /**
     * Author Bob
     * Date
     * Description
     **/
    public class Student extends Person {
    
        private String school;
    
        public Student (String name , String location, String school){
            this.school = school;
            this.name = name;
            this.location = location;
    
        }
    
        public String info (){
            return "name:" + name + "location:" +location + "school:"+school;
        }
    
        public static void main(String[] args) {
            Student student = new Student("李四","北京","北京外国语大学");
            System.out.println(student.info());
        }
    }
    
    
    评论

报告相同问题?

悬赏问题

  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元