类的继承 父类-子类 关键字 extends 新建一个父类 public class Person { private String name; private int age; public void run() { System.out.println("Person run"); } } public class Student extends Person { public void run() …
一.方法重载 如果子类中的方法与它的超类中的方法有相同的方法名,则称子类中的方法重载超类中的方法,特别是当超类和子类中的方法名和参数类型都相同时,在子类中调用该方法时,超类中的方法会被隐藏.考虑下面程序: class A { int i, j; A(int a, int b) { i = a; j = b; } // display i and j void show() { System.out.println("i and j: " + i + " " + j)…
继承:继承属于单继承,只能继承一个父类. 继承的一个结果是派生于基类的子类在方法和属性上有一定的重叠. 继承只能够同时继承与一个基类:可以同时继承一个基类和多个接口,但是基类必须放在第一个.(注:C#没有多继承,如果非得想用多继承形式,只能使用接口) using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespac…