标题:java中的重载与重写的理解
取消只看楼主
china7977494
Rank: 1
等 级:新手上路
帖 子:5
专家分:5
注 册:2012-12-17
结帖率:100%
已结贴  问题点数:20 回复次数:0 
java中的重载与重写的理解

1.重载必须在同一各类中吗?
Overloading in Java can occur when two or more methods in the same class share the same name
 or even if a child class shares a method with the same name as one of it’s parent classes.
2.重写必须在不同类中吗?
public class Test{
   public static void main(String[] args){
        System.out.println(new Test());
       System.out.println(new Test(){
        public String toString(){
             return "manual override";
         }
       });
      System.out.println(new Test(){
                public String gm(){
                    return  "manual gm";
               }
        }.gm());
     }  //end of main method

   public String gm(){
     return "gm";
    }
}
搜索更多相关主题的帖子: classes methods public 
2013-03-24 10:32



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-401753-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.055632 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved