当前位置: 首页 > news >正文

Java基础 5.10

1.方法重写课堂练习

package com.logic.override_;
//编写一个Person类 包括属性/private(name, age) 构造器 方法say(返回自我介绍的字符串)
//编写一个Student类 继承Person类 增加id score 属性/private 以及构造器
//定义say方法(返回自我介绍的信息)
//在main中 分别创建Person和Student对象 调用say方法输出自我介绍
public class OverrideExercise {public static void main(String[] args) {Student student = new Student("logic", 18, 100, 123);Person person = new Person("Lucy", 19);System.out.println(person.say());System.out.println(student.say());}
}
package com.logic.override_;public class Person {private String name;private int age;public Person(String name, int age) {this.name = name;this.age = age;}public String getName() {return name;}public void setName(String name) {this.name = name;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}public String say() {return "Hello " + name + " " + age;}
}
package com.logic.override_;public class Student extends Person {private double score;private int id;public Student(String name, int age, double score, int id) {super(name, age);this.score = score;this.id = id;}public double getScore() {return score;}public void setScore(double score) {this.score = score;}public int getId() {return id;}public void setId(int id) {this.id = id;}public String say() {return super.say() + ", score: " + score + ", id: " + id;}
}

 

http://www.dtcms.com/a/182886.html

相关文章:

  • JavaSE核心知识点02面向对象编程02-05(方法)
  • 《向上生长》读书笔记day5
  • Dockers部署oscarfonts/geoserver镜像的Geoserver
  • Ansible模块——从控制节点向目标主机复制文件!
  • 软考错题集
  • 使用互斥锁保护临界
  • (51单片机)LCD显示红外遥控相关数字(Delay延时函数)(LCD1602教程)(Int0和Timer0外部中断教程)(IR红外遥控模块教程)
  • Spring Cloud -3( 9000 字详解 Spring Cloud)
  • LVGL对象的盒子模型和样式
  • 大模型中的三角位置编码实现
  • WinCC V7.2到V8.0与S71200/1500系列连接通讯教程以及避坑点
  • C++学习之模板初阶学习
  • 数据治理框架在企业中的落地:从理念到实践
  • 第三章 Freertos智能小车遥控控制
  • 互联网大厂Java面试实录:Spring Boot与微服务架构在电商场景中的应用解析
  • 21.【.NET 8 实战--孢子记账--从单体到微服务--转向微服务】--单体转微服务--身份认证服务拆分规划
  • diy装机成功录
  • C++ learning day 02
  • day010-命令实战练习题
  • 第一个SpringBoot程序
  • 软考中级数据库备考-上午篇
  • Spark的三种部署模式及其特点与区别
  • Autoware播放提示音
  • 基于Spring Boot + Vue的高校心理教育辅导系统
  • adb命令查询不到设备?
  • QTableWidget实现多级表头、表头冻结效果
  • 模型 启动效应
  • WPF之集合绑定深入
  • 配置高级相关
  • 深入理解卷积神经网络的输入层:数据的起点与预处理核心