设为首页 加入收藏

TOP

2012年最新java笔试题带答案(二)
2014-11-23 23:35:27 来源: 作者: 【 】 浏览:13
Tags:2012年 最新 java 试题 答案


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 );


}


}



三. 程序设计题(第112分,第213分)


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)+”");


}


}




首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇TestDirector面试题:TestDirecto.. 下一篇考察软件的安全可靠性时,一般从..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: