多态阵列不起作用

时间:2017-09-12 15:20:42

标签: java

Select distinct
i.Postcode
, i.Number
    , case when i.[rank] = 1 then i.Occupant end as [First Tennant]
    , case when i.[rank] = 2 then i.Occupant end as [Second Tennant]
    , case when i.[rank] = 3 then i.Occupant end as [Third Tennant]
    , case when i.[rank] = 4 then i.Occupant end as [Fourth Tennant]
    , case when i.[rank] = 5 then i.Occupant end as [Fifth Tennant]

    from Reporting.dbo.Test u
            inner join RANKING i on i.Postcode = u.Postcode

我不知道为什么Postcode | Number | First Tennant | Second Tennant | Third Tennant | Fourth Tennant | Fifth Tennant | AA001AA | 12 | D | NULL | NULL | NULL | NULL | AA001AA | 12 | NULL | E | NULL | NULL | NULL | 无法找到package finalpaperpractice; public class PolymorphicTest { public void function(){ System.out.println("1"); } public static void main (String [] args){ Object obj [] = {new PolymorphicTest(), new A(), new B()}; for (int i = 0; i < 3; i ++){ obj[i].function(); // error on this line } } } class A{ public void function(){ System.out.println("2"); } } class B{ public void function(){ System.out.println("3"); } } 。 我编写了一个覆盖obj[i]的代码,该代码完美无缺,但这段代码并没有覆盖。

1 个答案:

答案 0 :(得分:2)

因为objObject类型且Object类没有声明function方法。

您可以使用function方法创建一个接口,并在所有类中的function方法中实现此接口。

然后,

Object obj

应该改为

<Your Interface> obj