方法过度问题..... [英] method overidden problem .....

查看:77
本文介绍了方法过度问题.....的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


class A

{

void test(int a)

{

System.out.println(正常...... A类);

}

}

B级扩展A

{

int test(int a)

{

系统.out.println(" B&B;);

}

}
class A
{
void test(int a)
{
System.out.println("Normal .... Class A");
}
}

class B extends A
{
int test(int a)
{
System.out.println("Class B");
}
}



i有这段代码。一个comiler错误来了....这里B级方法不能被覆盖.....为什么会发生这种情况


i认为..这是由于方法签名不匹配或其他任何东西...... plz解释,如果可能的话,plz详细解释我方法签名 .......



任何帮助都是最受欢迎的....

i have this code .. a comiler error comes .... here in class B the method can''t be overidden ..... why this happens

i think .. it is due to method signature mismatching or anything else ... plz explain and if possible plz explain me in details method signature .......


any help is most welcome ....

推荐答案


i有这个代码.. a comiler错误来了....在B级这个方法不能被覆盖.....为什么会发生这种情况


i认为......这是由于方法签名不匹配或其他任何原因... plz解释并且如果可能的话plz详细解释我方法签名。 ......


欢迎任何帮助....
i have this code .. a comiler error comes .... here in class B the method can''t be overidden ..... why this happens

i think .. it is due to method signature mismatching or anything else ... plz explain and if possible plz explain me in details method signature .......


any help is most welcome ....



DJ,如果你有时间请阅读这里的课程。


除了具有共变量返回类型的1.5之外,您不能覆盖返回类型。在那个代码中你有不同的返回类型,一个不是另一个的子类,所以不能工作。

DJ, if you do get time please read the classes here.

You cannot override on return types except in 1.5 with co-variant return types. In that code you have different return types and one is not a subclass of the other so that won''t work.


thanx for ur reply .....


但是我想告诉我......什么是方法签名以及它在mothod覆盖中的重要性....


thanxxxx
thanx for ur reply .....

but i think tell me ... what is method signature and how it is important in mothod override ....

thanxxxx


thanx for your reply .....


但告诉我......什么是方法签名以及它在mothod覆盖中的重要性......


thanxxxx
thanx for ur reply .....

but tell me ... what is method signature and how it is important in mothod override ....

thanxxxx


这篇关于方法过度问题.....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆