成都创新互联网站制作重庆分公司

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面向对象编程(封装/继承/多态)实例解析-创新互联
当前URL:http://cxhlcq.com/article/egosd.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部