。
class MySuper {
public long getLength(){
return 4;
}
}
public class SubDemo extends MySuper {
public long getLength(){
return 5;
}
public static void main (String[] args){
MySuper sooper = new MySuper();
SubDemo sub = new SubDemo();
System.out.println(sooper.getLength()+ “,” + sub.getLength());
}}
9. 请将下面程序填充完整:
class fruit extends Thread
{
public void run()
{
for(int i=0;i<5;i++)
{
System.out.println(i+” “+this.getName());
}
System.out.println(“done!”+getName());
}
}
class two
{
public static void main(String args[])
{
fruit f1=new fruit();
_________________________;//启动线程f1
}
}
10.以下是一个Applet,其功能为:在窗口中按右对齐方式摆放三个单选按钮。请将空白处填充完整。
import java.applet.Applet;
import java.awt.*;
public class test_layout6 extends Applet
{
CheckboxGroup optGroup;
Checkbox opt1, opt2, opt3;
public void init( )
{
___________________________________
//设定布局方式为顺序布局,并设定为按右对齐方式
optGroup = new CheckboxGroup();
opt1 = new Checkbox( “选项1″,optGroup, false );
add( opt1 );
opt2 = new Checkbox( “选项2″,optGroup, false );
add( opt2 );
opt3 = new Checkbox( “选项3″,optGroup, false );
add( opt3 );
}
}
三. 程序设计题(第1题12分,第2题13分)
1.请编写一个实现如下功能的Application:比较从键盘输入的两个整数是否相等,并根据比较结果显示“相等”或“不相等”。
2.请编写一个Applet,其中包含两个标签(一个用于给出提示信息,另一个用来输出结果)和一个文本框。要求从文本框中获取用户给出的一个整数,并将该数的绝对值在标签上输出。
答案
一.BDDAC,CADAA,BACBB
二.1。Main public static void main(String args[]),Applet
2。Continue 3。ArthmeticException 4。Abstract final
5.Import java.util.*; 6.length() 7.Sychronized 8.4,5
9.f1.start() 10.this.setLayout(new FlowLayout(FlowLayout.Right,5,5));
三.1. class add
{ public static void main(String args[])
{ int x=0,y=0;
try
{ x=Integer.parseInt(args[0]);
y=Integer.parseInt(args[1]); }
catch(NumberFormatException e)
{ System.out.println(“请输入两个整型参数!”);
System.exit(0);
}
if(x==y)
{System.out.println(“相等”);
}
else System.out.println(“不相等”); }
}
2. import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class button1 extends Applet implements ActionListener
{
Button b1=new Button(“button1″);
Label l1=new Label(“请输入一个整数”);
Label l2=new Label(“显示结果”);
TextField t1=new TextField(10);
public void init()
{
add(l1);
add(t1);
add(b1);
add(l2);
b1.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
int x=Integer.parseInt(t1.getText());
l2.setText(Math.abs(x)+”");
}
}