首页 > 编程语言 > 详细

Java 三大特性之继承

时间:2015-11-09 02:07:35      阅读:243      评论:0      收藏:0      [点我收藏+]

Java 三大特性之继承

继承可以不用重新编写已有的特性,同时又可以根据需求来覆写方法

父类:

?

public class Father {
	protected String getText(){
		return "I am Father";
	}
}

?

?

子类:

?

public class Son extends Father{
	protected String getText(){
		return "I am Son";
	}
}

?

?

客户端:

public class Main {

	public static void main(String[] args) {
		Father f=new Father();
		System.out.println(f.getText());
		
		Father f2=new Son();
		System.out.println(f2.getText());
	}
}

?运行结果:

I am Father
I am Son

?

?

?

?

Java 三大特性之继承

原文:http://hw1287789687.iteye.com/blog/2255599

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!