(String ... args)的值如何影响子类覆盖? [英] How does value of (String... args) affect in subclass overriding?

查看:128
本文介绍了(String ... args)的值如何影响子类覆盖?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果一个Alpha类的参数方法为 public void foo(String ... args)&尝试通过说 public void foo(String a)在子类Beta中覆盖相同的方法。并创建一个参考对象&实例化为子类Beta&试图从Alpha访问foo方法。它从Alpha类返回值而不是Beta Sub-class的值。

if a class Alpha has a method with arguments as public void foo(String... args) & same method is tried to be overridden in a sub-class Beta by say public void foo(String a).And a reference object is created & instantiated to subclass Beta & trying to access foo method from Alpha. Its returning the value from Alpha class instead of the value from Beta Sub-class .

它不能从BETA类返回值作为其初始化&分配Beta类对象?

Shouldnt it return the value from BETA class as its initialized & assigned Beta class Object ?

有什么区别b / w 方法(String ... args)& 方法(字符串a)

What is the difference b/w Method(String ... args) & Method(String a)?

推荐答案

这是因为 Beta 覆盖Alpha中的那个,因为它没有相同的形式参数。 String ... String 不同,就像 String []的方式 String 不同。

It's because the method in Beta does not override the one in Alpha because it does not have the same formal parameters. String... is not the same as String, much like the way String[] is not the same as String.

这篇关于(String ... args)的值如何影响子类覆盖?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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