总结:多态 ;、

当重写父类的方法的时,子类对象名可以调用父类的方法,以及不带参的构造方法

package com.addd;

public class rr {
	int a, b;
	String c;

	public void run() {
		System.out.println("java继承学习");
	}

	public void add(int a, int b) {
		int s = a + b;
		System.out.println(s);
	}

	public rr() {
		System.out.println("同一个舞台");
	}

}

class Yl extends rr {
	// String color="blue";
	public Yl() {// 这里父类有了带参的构造方法,子类不许继承调用它
		System.out.println("相继承父类的方法用super.方法名");

		// TODO Auto-generated constructor stub
	}

	public void read() {
		System.out.println("您呢你难男男女女难");
	}

	public void run() {
		super.run();// 我想继承父类的run()方法
		System.out.println("鱼儿的世界");
	}

	// 在这里重写方法要么不写带参的构造方法,要不写参构造方法

}

  

相关文章:

  • 2022-01-09
  • 2021-11-12
  • 2022-12-23
  • 2022-12-23
  • 2021-06-26
  • 2021-09-03
  • 2021-06-08
  • 2022-01-20
猜你喜欢
  • 2021-07-23
  • 2022-12-23
  • 2021-11-30
  • 2022-12-23
  • 2021-10-11
  • 2021-11-15
  • 2022-12-23
相关资源
相似解决方案