| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 793 人关注过本帖
标题:关于方法覆盖的菜菜
只看楼主 加入收藏
♂twincle
Rank: 1
等 级:新手上路
帖 子:28
专家分:0
注 册:2004-8-4
收藏
 问题点数:0 回复次数:1 
关于方法覆盖的菜菜

public class test{ public static void main(String args[]){ System.out.println("Hello World!!!") ; A a = new A(6) ; a.printresult() ; B b = new B(7) ; b.printresult() ; } }

class A{ public int x, y ;

A(int i){ x = i ; sendresult() ; }

public void sendresult(){ y = x * x ; }

public void printresult(){ System.out.println(y) ; } }

class B extends A{ }

在B类中我想通过构造函数向类中传递x,并利用方法的覆盖把y = x * x改成y = x + x,但是不知道那个super是怎么用的。~~请大家帮我把B类里面的东西补全~~谢谢

搜索更多相关主题的帖子: 菜菜 
2004-10-17 01:49
Anstey
Rank: 1
等 级:新手上路
帖 子:94
专家分:0
注 册:2004-4-14
收藏
得分:0 

class B extends A{

B (int i){ super(i); sendresult(); }

public void sendresult(){ y = x + x ; } }

class B is a subclass of A, in this case, if you have another method called sendresult which has the same method signiture as the one in its parent class, namely A, the one in the subclass, B, will be called first.


Anstey. Cheers. I love CAPPUCCINO~~
2004-10-17 07:51
快速回复:关于方法覆盖的菜菜
数据加载中...
 
   



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

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