java篇 【14】Java 继承

来源:互联网 发布:阿里云ecs搭建ss 编辑:程序博客网 时间:2024/05/17 02:30

1、类的继承的格式
class 父类{} // 定义父类
class 子类 extends 父类{} // 使用extends关键字实现继承


2、Person 与 student 类的继承图
----------------------------------------------- -------------------------------------------------------------------
Person(父类) Student(子类)
----------------------------------------------- -------------------------------------------------------------------
private Stringname; private String name;
private intage; private int age;
public voidsetName(String name){} 继承 public void setName(Stringname){} 从父类继承的操作
public voidsetAge(int age){} publicvoid setAge(intage){}
public StringgetName(){} publicString getName(){}
public int getAge(){} public int getAge(){}
----------------------------------------------- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
private String school;
public void setSchool(Stringschool); 自己定义的操作
public String getSchool(){};
-------------------------------------------------------------------


0 0