super例解
2094 ワード
/********************
* super
* :
* 。
* :
* 。
* ************************/
package com.aabnn.parent;
public class Parent {
protected String name;
protected boolean gender;
protected int age;
protected String hobby;
public Parent(){
}
public Parent(String name,boolean gender,int age,String hobby){
this.name=name;
this.gender=gender;
this.age=age;
this.hobby=hobby;
}
}
package com.aabnn.parent;
public class Son extends Parent{
private String company;
private String hobby;
public Son(){
super();
}
public String getCompany() {
return company;
}
public void setCompany(String company) {
this.company = company;
}
public String getHobby() {
return hobby;
}
public void setHobby(String hobby) {
this.hobby = hobby;
}
public String getParentName(){
return super.name;
}
public String getParentHobby(){
return super.hobby;
}
public Son(String name,boolean gender,int age,String hobby,String hobby1,String company){
super(name,gender,age,hobby);
this.hobby=hobby1;
this.company=company;
}
}
package com.aabnn.test;
import com.aabnn.parent.Son;
public class TestSuper {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Son son=new Son("shanzao",true,18,"basketball","sing","hotmail");
System.out.println("the father name of the son is:"+son.getParentName());
System.out.println("the father hobby is:"+son.getParentHobby());
System.out.println("the son hobby is:"+son.getHobby());
System.out.println("the company of the son is:"+son.getCompany());
}
}