上面回答的比较清楚了,我下面给你举个例子:
- package lh.zjzk;
- public class Parent {
- private String child1;
-
- public Parent() {
- }
-
- public Parent(String child1) {
- this.child1 = child1;
- }
- public void say(){
- System.out.println("我是家长");
- }
- public String getChild1() {
- return child1;
- }
- public void setChild1(String child1) {
- this.child1 = child1;
- }
-
- }
复制代码
子类 ZhangSan继承Parent,然后他也有一个say()方法,内容调用parent中的Say()
- package lh.zjzk;
- public class ZhangSan extends Parent {
- @Override
- public void say() {
- super.say();//调用父窗体的say()方法内容
- }
- public static void main(String[] args) {
- ZhangSan zs = new ZhangSan();
- zs.say();
- }
- }
复制代码
输出结果:我是家长 |