下面类的索引定义或使用正确的是()。
A: class MyClass{ int x; int y; public int this[int index] { get{ if (index==0) return x; else return y; }}}
B: class MyClass{ int x; int y; public int this[int index] { set{ if (index==0) x=value; else y=value; }}}
C: class MyClass{ int x; int y; public int INDEX[int index] { get{ if (index==0) return x; else return y; } set{ if (index==0) x=value; else y=value; }}}
D: class MyClass{ int x; int y; public int this[int index] { get{ if (index==0) return x; else return y; } set{ if (index==0) x=value; else y=value; }}}
A: class MyClass{ int x; int y; public int this[int index] { get{ if (index==0) return x; else return y; }}}
B: class MyClass{ int x; int y; public int this[int index] { set{ if (index==0) x=value; else y=value; }}}
C: class MyClass{ int x; int y; public int INDEX[int index] { get{ if (index==0) return x; else return y; } set{ if (index==0) x=value; else y=value; }}}
D: class MyClass{ int x; int y; public int this[int index] { get{ if (index==0) return x; else return y; } set{ if (index==0) x=value; else y=value; }}}
举一反三
- 在JSP页面中,下列( )代码能够正确的声明计算乘法的方法。 A: <;%!Public int mul(int x,int y){Return x*y ;}%>; B: <;%=public int mul(int x,int y){Return x*y ;}%>; C: <;%public int mul(int x,int y){%>;<;% returnx*y ;%>;<;%}%>; D: <;%Public int mul(int x,int y){Return x*y ;}%>;
- class A { public int f(int x,int y) { return x+y; } } class B extends A { public int f(byte x,int y) { return x*y; } } 子类B的对象只能调用子类中的f方法。( )
- 中国大学MOOC: 34. 下面是类MyClass的定义,对定义中各语句描述正确的是____。class MyClass{ public: void MyClass(int a){ X=a;} //① int f(int a,int b) //② { X=a; Y=b; } int f(int a,int b,int c=0) //③ { X=a; Y=b; } int f(int a,int b,int c=0) { X=a; Y=b; Z=c; } static void g(){ X=10;} //④ private: int X,Y,Z; };
- gcd (x,y)函数的功能是求x和y的最大公约数,在划线处填写正确的表达式: int gcd ( int x , int y) { if ( y == 0) return x; else return ____________________; }
- 假设输入5,10,以下程序运行的结果是( )。#include stdio.hint max(int a,int b){ if(a=b) return a; else return b;}int min(int a,int b){ if(a=b) return b; else return a;}void f(int a,int b,int(*p)(int,int)){ printf(%d\n,(*p)(a,b));}int main(){ int x,y; scanf(%d,%d,x,y); f(x,y,max); f(x,y,min); return 0;} A: 105 B: 55 C: 510 D: 1010