Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2534759
  • 博文数量: 245
  • 博客积分: 4125
  • 博客等级: 上校
  • 技术积分: 3113
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-25 23:56
文章分类

全部博文(245)

文章存档

2015年(2)

2014年(26)

2013年(41)

2012年(40)

2011年(134)

2010年(2)

分类: Java

2011-11-16 13:12:02


Method Overriding
Method overriding occurs when a subclass implements a method that is already implemented in a superclass. The method name must be the same, and the parameter and return types of the subclass's implementation must be subtypes of the superclass's implementation. You cannot allow less access than the access level of the superclass's method.
方法覆盖:一个子类实现一个在父类中已经存在的方法叫覆盖。
子类和父类方法名必须相同,子类中覆盖的方法的参数和返回值类型必须是父类中方法的参数的类型的子类型。子类覆盖方法的访问级别不能比父类中方法严格。
eg,

  1. class Timer {
  2.    public Date getDate(Country c) { ... }
  3. }

  4. class USATimer {
  5.    public Date getDate(USA usa) { ... }
  6. }

Where Usa extends Country.


Method Overloading
Method overloading is when two methods share the same name but have a different number or type of parameters.
方法重载:当两个方法具有相同的方法名,但是有不同数目或不同类型的参数。
eg,
  1. public void print(String str) { ...
  2. }
  3. public void print(Date date) { ...
  4. }






谢谢访问!

阅读(1120) | 评论(0) | 转发(0) |
0

上一篇:spring mvc实现ajax 分页

下一篇:Java Iterator

给主人留下些什么吧!~~