Java面向对象编程(封装/继承/多态)实例解析-创新互联
本文主要介绍了面向对象的三大特征实例解析,下面看看具体内容。
成都创新互联成都网站建设按需搭建网站,是成都网站建设公司,为成都花箱提供网站建设服务,有成熟的网站定制合作流程,提供网站定制设计服务:原型图制作、网站创意设计、前端HTML5制作、后台程序开发等。成都网站改版热线:13518219792封装
封装一个Teacher和Student类
package com.hz.test; public class Teacher { private String name; private String majorDirection; private String teachCourse; private int teachAge; public Teacher() { super(); } public Teacher(String name,String majorDirection,String teachCourse,int teachAge) { this.name = name; this.majorDirection = majorDirection; this.teachCourse = teachCourse; this.teachAge = teachAge; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getMajorDirection() { return majorDirection; } public void setMajorDirection(String majorDirection) { this.majorDirection = majorDirection; } public String getTeachCourse() { return teachCourse; } public void setTeachCourse(String teachCourse) { this.teachCourse = teachCourse; } public int getTeachAge() { return teachAge; } public void setTeachAge(int teachAge) { this.teachAge = teachAge; } public String toString() { return "姓名=" + getName() + ", 专业方向=" + getMajorDirection() + ", 所教课程=" + getTeachCourse() + ", 教龄=" + getTeachAge(); } }
当前名称:Java面向对象编程(封装/继承/多态)实例解析-创新互联
链接分享:http://hbruida.cn/article/egosd.html