JAVA基础练习题.doc
文本预览下载声明
JAVA练习
1. 以下方法fun的功能是求两参数之积。(return a*b)
int fun ( int a, int b ) { __________________; }
2. 以下方法fun的功能是求两参数之积。(return (float)a*b)
float fun ( int a, double b ) { __________________; }
3. 以下方法fun的功能是求两参数的最大值。(return ab?a:b)
int fun ( int a, int b ) { __________________; }
4. 以下方法m的功能是求两参数之积的整数部分。
(return (int)(a*b))
int m ( float x, float y ) { __________________; }
5. 下面是用户程序对 Applet 类中方法 paint( ) 的重新定义。
(void call)
public ___ paint(Graphics ____)
{ call.drawString(Hello,java!,10,20); }
6.下面方法的功能是判断一个整数是否为偶数,将程序补充完整。(boolean true)
public ________ isEven(int a)
{ if(a%2==0)
return _____;
else
return false;
}
7.同一个类中多个方法具有相同的方法名,不同的_____________称为方法的重载。(参数列表)
二.选择题及答案
1.下列方法定义中,正确的是( D )。
A) int x( int a,b ) { return (a-b); }
B) double x( int a,int b) { int w; w=a-b; }
C) double x( a,b ) { return b; }
D) int x( int a,int b) { return a-b; }
2.下列方法定义中,正确的是( D )。
A) void x( int a,int b ); { return (a-b); }
B) x( int a,int b) { return a-b; }
C) double x { return b; }
D) int x( int a,int b) { return a+b; }
3. 下列方法定义中,不正确的是(D)。
A) float x( int a,int b ) { return (a-b); }
B) int x( int a,int b) { return a-b; }
C) int x( int a,int b ); { return a*b; }
D) int x(int a,int b) { return 1.2*(a+b); }
4. 下列方法定义中,正确的是( A )。
A) int x( ){ char ch=a; return (int)ch; }
B) void x( ){ ...return true; }
C) int x( ){ ...return true; }
D) int x( int a, b){ return a+b; }
5. 列方法定义中,方法头不正确的是(D )。
A)public int x( ){ ... }
B)public static int x( double y ){ ... }
C)void x( double d ) { ... }
D)public static x( double a ){ ... }
6.在某个类中存在一个方法:void getSort(int x),以下能作为这个方法的重载的声明的是(C)。
A)public getSort(float x) B)int getSort(int y)
C)double getSort(int x,int y) D)void get(int x,int y)
7.在某个类中存在一个方法:void sort(int x),以下不能作为这个方法的重载的声明的是(B)。
A)public float sort(float x)
显示全部