作者: 谢达 时间: 2013-3-1 13:05
package com.ccsu.xie;
class Person{
private String name;
private int age;
public Person(String name,int age){
this.name = name;
this.age = age;
System.out.println("Person::"+name);
System.out.println("Person::"+age);
}
public void getName(){
System.out.println("Person");
}
}
class Student extends Person{
public Student(String name, int age) {
//通过super来调用父类中的构造方法,具体调用父类哪个构造函数取决与参数
super(name, age);
}
public void getName(){
//通过super.方法名来调用父类的中方法
super.getName();
}
}
public class SuperConsDemo {
public static void main(String[] args) {
Person p = new Student("zhangsan",40);
p.getName();
}