java中的多态性
方法重载是运行时多态性还是编译时多态性的一个例子?
Is method overloading is an example of runtime polymorphism or compile time polymorphism?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
方法重载是运行时多态性还是编译时多态性的一个例子?
Is method overloading is an example of runtime polymorphism or compile time polymorphism?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
Java 中没有运算符重载。
方法重写可实现运行时多态性;方法重载可以实现编译时多态性。
您可以在教科书中阅读更多相关内容。
另请参阅
There is no operator overloading in Java.
Method overriding enables run-time polymorphism; method overloading enables compile-time polymorphism.
You can read more about this in your textbook.
See also
方法重载和多态是两个完全不同的概念。多态性与继承相关,并确定从类层次结构的哪个级别调用该方法。方法重载是在同一位置创建两个具有相同名称且采用不同参数的方法。例如:
Method overloading and polymorphism are two completely different concepts. Polymorphism relates to inheritance and determines from which level of the class hierarchy the method is called. Method overloading is creating two methods in the same location with the same name that take different arguments. For instance:
方法重载是编译时绑定或静态绑定的示例
方法重载会导致多态方法,一个方法可以被定义多次,具有相同的名称和不同数量的方法参数或参数类型(java允许这样做),当发生这种情况时,方法调用和实际定义之间的链接就被解决了在编译时,因此重载称为编译时绑定或静态绑定。 OO程序语言的特点称之为编译时多态性。
Method overloading is example for compile time binding or static binding
method overloading results in polymorphic methods, a method can be defined more than one time having the same name and varying number either method parameters or parameter types (java allows to do this) , when this happens the linkage between method call and actual definition is resolved at compile time thus overloading is called compile time binding or static binding. OO Program language features call it has compile time Polymorphism.
方法重载是编译时绑定的示例。编译器只在编译时决定需要调用哪个方法,所以是编译时多态或者可以说静态绑定,但是方法重写是运行时多态,bcz在运行时,根据对象引用,方法调用被解析。
Method overloading is example of complie time binding. Compiler resolves which method needs to be called at compile time only, So it is compile time polymorphism or you can say static binding, But Method overriding is Runtime polymorphism, bcz at run time , depending on the object reference , method call is resolved.