您的位置:首页 > 其它

1.20作业

2016-01-20 20:15 218 查看
父类

package com.hanqi;

public class father {
public father (){
//System.out.println("父类的构造函数");
}
private String x1;

private String x2;

public String getX1() {
return x1;
}
public void setYuyin(String x1) {
this.x1 = x1;
}
public String getX2() {
return x2;
}
public void setYuhui(String x2) {
this.x2 = x2;
}

void   y1()
{
System.out.println("方法一");
}
void y2()
{
System.out.println("方法二");
}

}


子类覆盖

package com.hanqi;

public class Son extends father {
public Son()
{
System.out.println("子类构造函数");
}
public void y2()
{
System.out.println("子类重写方法");
}

}


向上转型

package com.hanqi;

public class ceshi2 {

public static void main(String[] args) {
// TODO 自动生成的方法存根
Son zl = new Son();

zl.y1();

zl.y2();

father fl = new father();

fl.y1();

fl.y2();
}

}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: