【多选题】给出如下代码 //接口 public interface Info { String show(int m, int n); } //类 public abstract class implements Info{ —————————— } 问:在类划线处,下列哪些定义是合法的?()
A. public String show(int m, int n) {}
B. public void show(int m, int n) {}
C. protected String show(int m, int n) {}
D. public Object show(int m,int n) {}
E. public abstract String show(int m, int n);
F. 其他定义都不合法
A. public String show(int m, int n) {}
B. public void show(int m, int n) {}
C. protected String show(int m, int n) {}
D. public Object show(int m,int n) {}
E. public abstract String show(int m, int n);
F. 其他定义都不合法
举一反三
- 给出下列【代码】注释标注的代码的输出结果。abstract class A {abstract int get(int a,int b);}public class E {public static void main(String args[]) {A a=new A() {public int get(int a,int b){return a+b;}};int m = a.get(2,5);a=new A() {public int get(int a,int b){return a*b;}};int n = a.get(2,5);System.out.printf("%d:%d",m,n);//【代码】}}
- 阅读程序题(给出【代码】注释标注的代码的输出结果)interface Com {int add(int a, int b);public static int get(int n){return n;}public default int see( int n){return n;}public default int look( int n) {return n;}}class A implements Com{public int add( int a, int b) { return a + b;}public int see(int n){ return n + 1;}}public class 习题5_阅读4{public static void main( String args[ ]) {A a = new A();int m = a.add(12,6);int n = Com.get( 12);int t = a.see(6);int q = a.look(6);System.out.printf("%d:%d:%d:%d",m,n, t,q); //【代码】 }}}
- (6-2)定义如下Person类,(1)处合理的代码是。 class Person { String name, department; int age; public Person(String n) { name = n; } public Person(String n, int a) { name = n; age = a; } public Person(String n, int a, String d) { ① department = d; } }
- 在下列类族声明的代码中,正确的访问类N的成员a的语句为 。 class N { public: int a; void display(){cout<<″A::a=”<<a<<endl;} }; class A:public N { public: int a1; }; class B:public N { public: int a2; }; class C :public A,public B { public : int a3; void show{cout<<″a3=″<<a3<<endl;} }; int main { C c1;//定义C类对象c1 ┆ }
- 有如下类定义:class AA{ int a;public: AA(int n=0):a(n){ }};class BB:public AA{ int b;public: BB (int m,int n)____________};下列选项中,能够填入下划线处的正确语句片段是( )。 A: :BB(m){a=n;} B: :BB(m),AA(n){} C: :AA(n) ,BB(m) {} D: :AA(n){b=m;}