class A{protected int method1(int a,int b){return 0;}}Which two are valid in a class that extends class A?哪两项正确,为什么?A.public int method1(int a,int b){return 0;} ivate int method1(int a,int b){return 0;} ivate int method1(int a,long b){return 0;}D.public short method1(int a,int b){return 0;} atic protected int method1(int a,int b){return 0;}

热心网友

抱歉应该是 A C继承父类是有条件的,这道题应该考的是Java中的覆盖和重载,B属于覆盖,但是覆盖必须满足子类的限制域大于父类的域,比如C中的private属性是比其父类中protected属性使用范围更大的的限制域。而C很明显是重载,看上去虽然是和父类函数一样,但是其入口参数不同(一个是2个Int型,一个是1个Int型1个Long型),Java是将其作为两个不同函数来处理的。