计算机类二级JAVA

JAVA程序设计试卷(三)

38 题含答案JAVA
共 38 题返回本类
1单选题1 / 38
Java application中的主类需包含main方法,以下哪项是main方法的正确形参?(    )
查看答案
B. String  args[]
4单选题4 / 38
若有定义:byte[] x={11,22,33,-66};
其中0≤k≤3,则对x数组元素错误的引用是(  )
查看答案
C. x[k+5]
5单选题5 / 38
Java Applet在被浏览器加载的时候首先被执行且在applet整个生命周期中只被运行一次的方法是(    )?
查看答案
A. init()
6单选题6 / 38
在浏览器中执行applet 程序,以下选项中的哪个方法将被最先执行(    )。
查看答案
A. init()
7单选题7 / 38
在Java中,一个类可同时定义许多同名的方法,这些方法的形式参数的个数、类型或顺序各不相同,传回的值也可以不相同。这种面向对象程序特性称为(    )
查看答案
C. 重载
8单选题8 / 38
以下有关构造方法的说法,正确的是:(    )
查看答案
A. 一个类的构造方法可以有多个
9单选题9 / 38
类Parent、Child定义如下:
1\.    public class  Parent
2\.{ public  float  aFun(float a, float b)  throws
3\.  IOException {      }
4\.}
5\.public  class  Child  extends  Parent{
6\.
7\.}
将以下哪种方法插入行6是不合法的。(    )
查看答案
A. float  aFun(float  a,  float  b){ }
10单选题10 / 38
给出下面代码,关于该程序以下哪个说法是正确的?(    )
public class Person{
static int arr[] = new int[5];
public static void main(String a[])
{
System.out.println(arr[0]); }
}
查看答案
C. 输出零
11单选题11 / 38
在编写Java  Applet程序时,需在程序的开头写上(    )语句。
查看答案
B. import  java.applet.Applet ;
12单选题12 / 38
下列类定义中哪些是合法的抽象类的定义?(    )
查看答案
C. abstract class Animal{abstract void growl();}
13单选题13 / 38
在使用interface声明一个接口时,只可以使用(    )修饰符修饰该接口。
查看答案
D. public
14单选题14 / 38
在使用interface声明一个接口时,只可以使用(    )修饰符修饰该接口。
查看答案
D. public
17单选题17 / 38
给定下列表达式
Integer I= new Integer(42);
Long  L= new Long(42);
Double D= new Double(42.0);
则下列表达式输出为true的是_____
查看答案
D. (I.equals (D))
18单选题18 / 38
请问所有的异常类皆继承哪一个类?(  )。
查看答案
B. java.lang.Throwable
19单选题19 / 38
进行Java基本的GUI设计需要用到的包是(    )。
查看答案
C. java.awt
20单选题20 / 38
当点击鼠标或者拖动鼠标时,触发的事件是下列的哪一个?(    )
查看答案
D. MouseEvent
22填空题22 / 38
数组x定义:String x[ ][ ]=new int[3][2];  x[0 ][0 ]=”abc”, x[0 ][1]=”12345”;
则 x.length 的值为__,x[0][1].length( ) 的值为__。
查看答案
  1. 6
  2. 5
25填空题25 / 38
当程序中需要抛出异常时,应该使用__子句,当需要在方法中声明可能抛出的异常类型,应该使用__子句。
查看答案
  1. throw
  2. throws
29判断题29 / 38
构造函数用于创建类的实例对象,构造函数名应与类名相同,返回类型为void。 (    )
查看答案
B. 错误
30判断题30 / 38
在异常处理中,若try中的代码可能产生多种异常则可以对应多个catch语句,若catch中的参数类型有父类子类关系,此时应该将父类放在后面,子类放在前面。        (    )
查看答案
A. 正确
31判断题31 / 38
在定义数组时不能够直接进行内存分配,如:char ch[10];是错误的定义语句(    )
查看答案
A. 正确
32判断题32 / 38
拥有abstract方法的类是抽象类,但抽象类中可以没有abstract方法。(    )
查看答案
A. 正确
33主观题33 / 38
以下程序段的输出结果为                      。
public  class  TestArray
{
public  static  void  main(String  args[ ]){
int  i , j ;
int  a[ ] = { 5,9,6,8,7};
for  ( i = 0 ; i < a.length-1; i ++ ) {
int  k = i;
for  ( j = i ; j < a.length ;  j++ )
if  ( a[j]<a[k] )  k = j;
int  temp =a[i];
a[i] = a[k];
a[k] = temp;
}
for  ( i =0 ; i<a.length; i++ )
System.out.print(a[i]+"  ");
System.out.println( );
}
}
查看答案
5 6 7 8 9
34判断题34 / 38
写出以下程序的运行结果。
import    java.io.*;
public    class  ATest{
public  static  void  main(String args[]) {
SubClass    sb = new  SubClass( );
System.out.println(sb.fun( ));
}
}
class    SuperClass{
int  a =24 , b =5 ;
}
class  SubClass  extends  SuperClass{
int  fun( ) {  return  a%b;  }
查看答案
35主观题35 / 38
写出以下程序的运行结果。
public class TryCatchFinally{
static void Proc( int sel ){
try{
if( sel==0 ){System.out.println("no Exception ");
return;}
else if( sel==1 ){  int i=0;        int j=4/i;}
}
catch( ArithmeticException e ) {
System.out.println("Catch "); }
catch( Exception e ) {
System.out.println("Will not be executed");}
finally{
System.out.println("finally");     }
}
public static void main( String args[] ){
Proc( 0 );     Proc( 1 );     }
}
查看答案
no Exception
finally
Catch
finally
36主观题36 / 38
阅读程序段,回答问题:
public class ClassA{
public void method1(int i){}
public void method2(int i){}
public static void method3(int i){}
public static void method4(int i){}
}
public class  ClassB extends ClassA{
public static void method1(int i){}
public void method2(int i){}
public void method3(int i){}
public static void method4(int i){}
}
ClassB中(method1、method2、method3、method4)四个方法,方法
_________ 覆盖了父类方法;方法 _________ 隐藏了父类方法。
查看答案
method2,  method4
37简答题37 / 38
(6分) 编写一个输出"Hello  World!"的程序,用两种方式实现(Application、Applet)。
①Application(2分)
②Applet(4分)
查看答案
a .public class Hello{
public static void main(string args[])
{System.out.println(“Hello World!”);}
}
b. import java.awt.Graphics;
import.java.applet.Applet;
public class HelloApplet extends Applet{
public void paint(Graphics g)
{g.drawString(“Hello World!”,20.20);
}
}
38连线题38 / 38
编写Application程序,使程序运行后在屏幕上生成如下图案:
  
窗口中包含有一个文本框,一个标签,两个按钮,当按下“文本一”按纽时,使得Hello java!显示在文本框中,按下“文本二”按纽时,使得“你好 Java!” 显示在文本框中(要求两个按纽之间使用网格布局,与其他组件共使用JFrame,默认布局管理)。程序头部已给出,请写出剩余代码部分。
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Lx9_4 implements ActionListener {
JFrame f;
JPanel p;
JTextField text1;
JLabel j;
JButton b1,b2;//下面代码由你续写
查看答案
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Lx9_4 implements ActionListener {
JFrame f;
JPanel p;
JTextField text1;
JLabel j;
JButton b1,b2;
public Lx9_4(){
f=new JFrame("Lx9_4按钮转换文字");
p=new JPanel();
j=new JLabel("Lx9_4习题演示");
p.setLayout(new GridLayout(1,2));
text1=new JTextField(30);
b1=new JButton("文本一");
b2=new JButton("文本二");
b1.setActionCommand("t1");
b2.setActionCommand("t2");
b1.addActionListener(this);
b2.addActionListener(this);
p.add(b1);
p.add(b2);
f.getContentPane().add(text1,BorderLayout.NORTH);
f.getContentPane().add(p,BorderLayout.CENTER);
f.getContentPane().add(j,BorderLayout.SOUTH);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.pack();
f.setVisible(true);
}
public void actionPerformed(ActionEvent Eve){
if(Eve.getActionCommand().equals("t1")){
text1.setText("Hello Java!");
}
else if(Eve.getActionCommand().equals("t2")){
text1.setText("你好 Java!");
}
}
public static void main(String a[]){
Lx9_4 c1=new Lx9_4();
}
}
← 上一卷下一卷 →