Java语言程序设计测试题改错题部分
2023-07-06
判断下面的程序片断是否正确。若有错,指出错在哪里并改正;若正确,打“√”。
1、 (max为整型变量)
if (max1)
g.drawString(“不等于1”, 20,20);
2、 for(float i=0.0;i>-10.0; i -=1.0)
System.out.println(i);
3、 void test(int x)
System.out.println(x);
return x;
4、abstract final class OurClasses
5、final MAX_NUMBER;
MAX_NUMBER++;
6、class MyClass
int var=100;
static int getVar()
return var;
7、public class MyClass
int data;
void MyClass(int d)
data=d;
8、public class MyMain
public static void main(String args[ ])
System.out.println(MyClass1.data);
class MyClass1
int data=10;
9、class IamAbstract
final int f;
double d;
abstract void method();
10、class parent
private int mine;
class child extends parent
int getMine()
return mine;
11、class parent
private int mine;
int getMine( )
return mine;
class child extends parent
int mine;
int getMine( )
return super.getMine;
12、class Parent
int field;
class Child extends Parent
int field;
class UseChild
static int getField(Child c)
return (c.field);
public class MainClass
public static void main(String args[ ])
Parent p=new Parent();
System.out.println(UseChild.getField(p));
13、class AmIRight
int field1=10;
abstract void method1( );
14、class AmIWrong
int data1,data2;
AmIWrong()
data1=-1;
AmIWrong(int d)
data2=d;
this();
15、interface MyInterface
void method1();
abstract class Parent implements MyInterface
class Child extends Parent
16、interface MyInterface
void method1();
abstract class Parent implements MyInterface
class Child extends Parent
void method1()
System.out.println(“I am implemented now!”);
17、public static void main(String args[ ])
try
char ch=(char)System.in.read();
. . .//其他语句
catch(Exception e)
return;
catch(IOException e)
System.out.println(e.toString());
18、public class AmIWrong implements Runnable
Thread mt=Thread(this);
mt.start();
void run()
System.out.println(“I am alive now”);
19、class MyClass1
final void method1()
void method1(int i)
20、说明以下程序是否有误,错在哪里,应如何改正。
public class MyApplet extends Applet
Label MyLabel;
public void init(String args[ ])
MyLabel=new Label(“Can you see me?”);
add(MyLabel);
21、说明下面程序是否有误,错在哪里,应如何改正。
import java.applet.*;
import java.awt.*;
public class AmIWrong extends Applet implements ActionListener
Button btn;
public void init()
btn=new Button(“Push Me”);
add(btn);
public void actionPerformed(ActionEvent e)
(Button)e.getSource().setLabel(“Pushed!”);
22、int array[10];
for(int j=0; j
array[j]=j+1;
23、说明下面程序是否有误,错在哪里,应如何改正。
public class UseVector
public static void main(String args[ ])
Vector myv;
for(int j=0; j