//通过super调用父类构造方法和隐藏方法 package mypack; class Father { public Father() { // TODO Auto-generated constructor stub System.out.println("null father"); } public Father(String name) { System.out.println("name = " + name); } public String toString() { // TODO Auto-generated method stub return "我是father"; } } class Sun extends Father { int age = 20; public Sun() { // TODO Auto-generated constructor stub super("铁鹏"); } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String toString() { // TODO Auto-generated method stub return super.toString(); } } public class DemoFive { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Sun sun = new Sun(); System.out.println(sun.toString()); ; } }
时间: 2024-10-13 06:37:02