作者ynchang (乱入的可怜虫)
看板java
标题Re: 有关继承的问题
时间Thu May 18 07:52:23 2006
※ 引述《ogamenewbie (荷兰烂银行)》之铭言:
: 避免 pcman 使用者误触阵亡. 原文砍除.
: ※ 引述《[email protected] (双面虎)》之铭言:
: 程式码如下 麻烦各位高手们帮忙
: class Parent {
: int i = 30;
: int sum(int j) {
: return i+j;
: }
: //////////////////////////////////////////////////////////////////////////////
: // int sum()//为何去掉这段程式码编译就不过 错误讯息如下 //
: // {return 333;}//ex.java:25: sum(int) in Parent cannot be applied to () //
: // System.out.println("p.sum():" + p.sum() + " p.sum(20):" + p.sum(20));//
: // //
: //////////////////////////////////////////////////////////////////////////////
: }
-------------------------略-------------------------------
: public class ex {
: public static void main(String[] argv) {
: Child c = new Child();
: test(c);
: }
: static void test(Parent p) {
^^^^^^^^他是Parent型态的
: System.out.println("p.sum():" + p.sum() + " p.sum(20):" + p.sum(20));
: } //^^^^^^40 ^^^^^^^^50
Parent并没有提供sum()这种method
只有sum(int)这种method
所以会发生"编译"错误....
: }
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 59.114.41.50