class Line{
private int x,y;
public Line(int x,int y){
this.x=x;
this.y=y;
}
}
举一反三
- 以下代码中,this表示。 class Bird { int x, y; void fly(int x, int y) { this.x = x; this.y = y; } }
- 下列代码中的“this”指的是( )class bird{int x,y;void fly(int x,int y){this.x=x;this.y=y;} }
- 下面类的索引定义或使用正确的是()。 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; }}}
- 中国大学MOOC: 有以下类定义class Point {public: Point(int x = 0, int y = 0) { _.x = x; _.y = y; } void Move(int xOff, int yOff) { _x += xOff; _.y += yOff; } void Print() const { cout << ( << _x << , << _y << ) << endl; }private: int _x, _y;};下列语句中会发生编译错误的是
- 中国大学MOOC: 定义类A如下:class A{ int a,b,c; public void B(int x,int y, int z){ a=x;b=y;c=z;}}
内容
- 0
有如下类定义:public class S extends F{S(int x){ }S(int x,int y) {super(x,y);}}则类F中一定有构造方法
- 1
下列类的定义中,正确的是() A: class a{int x=0;int y=1;}; B: class b{int x;int y=:1;}; C: class c{int x;int y;}; D: class d{int x=0,int y=1;};
- 2
分析程序,将代码补充完整class A { private int x; public A(int i) { x = i; } } class B extends A { private int y; public B(int i) { ___________ ____; y = i; } }
- 3
在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 ;}%>;
- 4
已定义类Aclass:class Aclass {private int x = 1;protected int y = 2;public int z = 3;public int sumA(){ return(x +y +z ); }}再通过继承与扩展定义子类Bclass:class Bclass extends Aclass {private A: s += b; B: s += x; C: s += z; D: s += y;