Skip to main content

Java 继承和多态

Yujie LiuLess than 1 minuteComputer ScienceProgramming LanguageJava

Java 继承和多态

继承

子类会隐式调用父类的构造函数

public class Solution {
    public Solution(){
        System.out.println("MainClass");
    }
  
  	public static void main(String[] args) {
    		SubClass subClass = new SubClass();
		}
}

public class SubClass extends Solution{
    public SubClass(){
        System.out.println("SubClass");
    }
}

输出为:

MainClass
SubClass
Last update:
Contributors: Yujie