在java中重写和重载 [英] overriding and overloading in java

查看:74
本文介绍了在java中重写和重载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当你覆盖一个方法时,是否有人能告诉我是否也会考虑该方法的返回类型?我的意思究竟是当你重写一个方法时返回类型是否可以不同。我读到的某些地方就像重载一样不会受到多态性的影响。这是真的吗?

Can anyone tell me whether the return type of the method will also be considered when you are overriding a method? what i mean exactly is whether the return type can be different when you are overriding a method.and somewhere i read like overloading will not come under polymorphism. is this true?

推荐答案


任何人都可以告诉我当你的方法是否也会考虑方法的返回类型覆盖方法?我的意思究竟是当你重写一个方法时返回类型是否可以不同。我读到的某些地方就像重载一样不会受到多态性的影响。这是真的?
Can anyone tell me whether the return type of the method will also be considered when you are overriding a method? what i mean exactly is whether the return type can be different when you are overriding a method.and somewhere i read like overloading will not come under polymorphism. is this true?



你有没有读过关于泛型的东西?

Have you read anything about generics yet?



任何人都可以告诉我是否在覆盖方法时也会考虑方法的返回类型?我的意思究竟是当你重写一个方法时返回类型是否可以不同。我读到的某些地方就像重载一样不会受到多态性的影响。这是真的?
Can anyone tell me whether the return type of the method will also be considered when you are overriding a method? what i mean exactly is whether the return type can be different when you are overriding a method.and somewhere i read like overloading will not come under polymorphism. is this true?



试试这样的事情:

Just try something like this:

展开 | 选择 | Wrap | 行号


你当你只有一个班级时,不能谈论覆盖。

你需要一个类中的方法与该类的超类中的方法具有相同的签名
You cannot talk about overriding when you have only one class.
You need a method in a class with the same signature as a method in a super class of that class


这篇关于在java中重写和重载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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