第11章 接口与内部类

第11章 接口与内部类

1、接口的定义和实现
2、内部类的使用
3、接口和内部类的意义

Java程序设计中的接口,也是一种规范。这个接口定义了类应该做什么?
但不关心如何做?即接口中只有方法名,没有具体实现的方法体。

用关键字“interface”来声明。

interface school{
  void setSchoolName(String schoolName);
  void setClassName(String schoolClassName);
}

类实现接口时要使用implements关键字。
class student implements school{
  private String schoolName;
  private String className;
  

  public void setSchoolName(String schoolName){
    this.schoolName = schoolName;
  }
  public void setClassName(String className){
    this.className = className;
  }
  public String tostring(){
    String infor = "学校名称:" + schoolName + " " + "班级名称:" + " " + className;
    return infor;
  }
}

public class schoolTest{
  public static void main(String[] args){
    student st = new student();
    st.setSchoolName("重庆大学");
    set.setClassName("计算机一班");
    System.out.println(st.tostring());
  }
}

posted @ 2016-11-29 20:40  程序建筑民工  阅读(150)  评论(0编辑  收藏  举报