本文主要介绍了面向对象的三大特征实例解析,下面看看具体内容。封装封装一个Teacher和Student类package com.hz.test;public class Teacher { private String name; pr
本文主要介绍了面向对象的三大特征实例解析,下面看看具体内容。
封装
封装一个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(); }}
--结束END--
本文标题: Java面向对象编程(封装/继承/多态)实例解析
本文链接: https://www.lsjlt.com/news/222091.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-04-29
2024-04-29
2024-04-29
2024-04-29
2024-04-29
2024-04-29
2024-04-29
2024-04-29
2024-04-29
2024-04-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0