标签:blog ar os sp java on div log bs
//通过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()); ; } }
标签:blog ar os sp java on div log bs
原文地址:http://www.cnblogs.com/wikiki/p/4130031.html