java篇 【14】Java 继承,
分享于 点击 29720 次 点评:257
java篇 【14】Java 继承,
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(){};
-------------------------------------------------------------------
相关文章
- 暂无相关文章
用户点评