注意:此页面搜索的是所有试题
国家开放大学面向对象程序设计
public class XXK2 {
private int a;
public XXK2() {a=3;}
public XXK2(int aa) {a=aa;}
public double f1() {
return 2*Math.pow(a,3)+a;
}
public static void main(String[] args) {
XXK2 x=new XXK2(), y=new XXK2(5);
System.out.println(x.f1()+", "+y.f1());
}
}

【A.】58.0, 256.0
【B.】57.0, 255.0

public class XXK2 {
private final int a;
public XXK2(int a) {this.a=a;}
public int f1(int x) {
if(x%2==1) return 2*(a+x);
else return 3*a+x;
}
public int get() {return a;}
public static void main(String[] args) {
XXK2 x=new XXK2(8);
int y=x.f1(20);
y+=x.get();
System.out.println("y="+y);
}
}


【A.】y=52
【B.】y=54

Java语言中的每个类都隐含着继承一个父类,这个父类为( )。
【A.】super
【B.】father
【C.】Java.lang.Object
【D.】class.dad

在派生类的构造方法中调用父类构造方法时,其语句关键字为( )。
【A.】Object
【B.】super
【C.】father
【D.】mother

Java语言中的类的层次结构为( )结构。根节点为( )类。
【A.】树状 Object
【B.】数组 int
【C.】文件 math
【D.】树状 root

Java语言中的一个类只能有( )个父类,可以有( )个派生类。
【A.】一 一
【B.】一 多
【C.】多 一
【D.】多 多

class Rectangle {
private int a,b;
public Rectangle(int aa, int bb) {a=aa; b=bb;}
public int area() {return a*b;}
public int girth() {return 2*(a+b);}
}

public class XXK3 extends Rectangle {
private int c;
public XXK3(int aa, int bb, int cc) {super(aa,bb); c=cc;}
public int volume() {return area()*c;}
public int arrisLength() {return 2*girth()+4*c;}

public static void main(String[] args) {
XXK3 x=new XXK3(1,3,5);
int y1=x.volume();
int y2=x.arrisLength();
System.out.println(y1+", "+y2);
}
}

【A.】20, 40
【B.】15, 36

class Rectangle {
private int a,b;
public Rectangle(int aa, int bb) {a=aa; b=bb;}
public int area() {return a*b;}
public int girth() {return 2*(a+b);}
}

public class XXK3 extends Rectangle {
private int c;
public XXK3(int aa, int bb, int cc) {super(aa,bb); c=cc;}
public int volume() {return area()*c;}
public int arrisLength() {return 2*girth()+4*c;}

public static void main(String[] args) {
XXK3 x=new XXK3(2,3,4);
int y1=x.volume();
int y2=x.arrisLength();
System.out.println(y1+", "+y2);
}
}

【A.】24, 36
【B.】26, 38

abstract class Shape {
int a,b;
public Shape(int aa, int bb) {a=aa; b=bb;}
abstract public double area();
}
class Rectangle extends Shape {
public Rectangle(int aa, int bb) {super(aa,bb);}
public double area() {return a*b;}
}
class Triangle extends Shape {
public Triangle(int aa, int bb) {super(aa,bb);}
public double area() {return a*b/2;}
}

public class XXK3 {
public static void main(String[] args) {
Shape x,y;
x=new Rectangle(10,20);
y=new Triangle(10,15);
System.out.println(x.area()+", "+y.area());
}
}

【A.】200.0, 75.0
【B.】400.0, 150.0

interface Shape {
double area();
double girth();
}
class Rectangle implements Shape {
int a,b;
public Rectangle(int aa, int bb) {a=aa; b=bb;}
public double area() {return a*b;}
public double girth() {return 2*(a+b);}
}

public class XXK3 {
public static void main(String[] args) {
Shape x;
x=new Rectangle(5,8);
System.out.println(x.area()+", "+x.girth());
}
}



【A.】40.0, 26.0
【B.】80.0, 42.0

abstract class Shape {
int a,b;
public Shape(int aa, int bb) {a=aa; b=bb;}
abstract public double area();
}
class Rectangle extends Shape {
public Rectangle(int aa, int bb) {super(aa,bb);}
public double area() {return a*b;}
}
class Triangle extends Shape {
public Triangle(int aa, int bb) {super(aa,bb);}
public double area() {return a*b/2;}
}

public class XXK3 {
public static void main(String[] args) {
Shape x,y;
x=new Rectangle(5,8);
y=new Triangle(5,8);
System.out.println(x.area()+", "+y.area());
}
}

【A.】40.0, 20.0
【B.】80.0, 40.0

interface Shape {
double area();
double girth();
}
class Rectangle implements Shape {
int a,b;
public Rectangle(int aa, int bb) {a=aa; b=bb;}
public double area() {return a*b;}
public double girth() {return 2*(a+b);}
}

public class XXK3 {
public static void main(String[] args) {
Shape x;
x=new Rectangle(6,10);
System.out.println(x.area()+", "+x.girth());
}
}


【A.】60.0, 32.0
【B.】80.0, 42.0

假定一个字符串对象x的值为"abc",则x.equals("acb")的值为( )。
【A.】True
【B.】NULL
【C.】False
【D.】"ab"

假定一个一维数组的定义语句为“int[]x=new int[20];”,则x.length的值为( )。
【A.】19
【B.】20
【C.】21
【D.】不确定

假定二维数组x中的一个元素为x[2][3],则它的行下标和列下标分别为( )和( )。
【A.】1 2
【B.】2 3
【C.】3 4
【D.】3 2