Java Test Twelve

本文深入探讨Java编程语言的核心概念和技术细节,包括类的设计、方法覆盖、异常处理、线程实现等关键主题,并提供了丰富的示例代码帮助理解。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

10. 任何的Applet都完全不能访问本地资源.(是/否?)

7、方法签名(或者特征)是指方法名和(?)、(?)、(?)
8、Java事件处理包括建立事件源、( )和( )
9、JavaBeans的属性分为简单属性、( )、( )、( )。
10、Jsp指令的作用是( )

 

 

12. 哪一个输出-4.0       C
A、 System.out.println(Math.floor(-4.7));
B、 System.out.println(Math.round(-4.7));
C、 System.out.println(Math.ceil (-4.7));
D、 System.out.println(Math.min(-4.7));

 

what is the result?  C
A、The code compiles and “s=” is printed
B 、The code complies and “s=null” is printed
C 、The code does not compile because string s is not initialized
D 、The code does not compile because string s can not be referenced
E 、The code compiles, but a NullPointException is thrown when tostring is called

 

 

16.下例操作的结果是什么? 4
System.out prinln(4|3);
1)6
2)0
3)1
4)7

2.paint()方法使用哪种类型的参数? A

A Graphics

B Graphics2D

C String

D Color

 

5.运行下列程序, 会产生什么结果 D

public class X extends Thread implements Runable{

 public void run(){

  System.out.println("this is run()");

 }

 public static void main(String args[])

 {

  Thread t=new Thread(new X());

  t.start();

 }

}

2、 GenericServlet是一个与协议相关的Servlet类。 (√)

7、J2EE Web层组件指(JSP )、(Serlvet)和可选的(JavaBean)

8、在使用Statement类的对象向数据库发送SQL语句时,如果发送的时select语句应该调用(executeQuery())方法,如果发送的是insert/update/delete语句一个调用(executeUpdate())方法。

9、在J2EE Web应用中使用MVC设计模式, JSP充当( view),Servlet充当(control ),可选的JavaBean充当(model )。

10、使用JDBC访问数据库中的存储过程,应该使用(prepareCall())

 

 

12、哪二种声明防止方法覆盖? A、D
A、final void methoda() {}
B、void final methoda() {}
C、static void methoda() {}
D、static final void methoda() {}
E、final abstract void methoda() {}

 

/******************

应该查找的

*******************/

6、从对象到类是一个(?)的过程。

11、ServletSocket所做的工作是:(?)

 

15、在web应用中处理会话有以下四种方式?
1)( )
2)( )
3)( ) 
4)( )

 

 

/******************

关于数组直接付值与new付值 :anar1和anar其实是一个意思,都可以。不会报错.

*******************/

8. 编译和执行下例代码会出现什么情况? 3
public class Q{
    public static void main(String argv[]){

//    int anar1[]={1,2,3};
      int anar[]=new int[]{1,2,3};
      System.out.println(anar[1]);
   }
}

1)1
2)Error: anar is referenced before it is initialized
3)2
4)Error : size of array must be defined

 

/******************

关于方法参数是byte类型时的错误,当某方法参数是byte类型时,不可以直传整数,因为那样编译器会把你传的23隐示当做int型的,所以这时跟你要使用方法参数byte类型不匹配会报错。

*******************/

10. class Student{
    private String name;
    private byte age;
      public Student(String name, byte age){
         this.age = age;
         this.name = name;
      }
//完成代码
}
public class Test{
     public static void main(String[] arg){
     Student stu1 = new Student(“Alice”, 23); //此句有错,请将正确的语句写在下面

byte by = 23;
     Student stu1 =new Student(“Alice”,by) ;
     System.out.println(stu1);
     }
}

 

 

Student(){

}
      Student(){

}

private String name;
      private byte age;
      private boolean married;

    public void setName(String name){

       this.name= name;

}

public String getName(){

return name;

}

    public void setAge(byte age){

       this.age= age;

}

public byte getAge(){

return age;

}

    public void setMarried(boolean married){

       this. married = married;

}

public boolean getMarried (){

return married;

}

7.下列语句序列执行后,x 的值是( )。
int a=3, b=4, x=5;
if( ++a

A) 5 B) 3 C) 4 D) 6
8.下列语句序列执行后,k 的值是( )。
int i=6, j=8, k=10, n=5, m=7;
if( i
A) 9 B) 10 C) 11 D) 12

 

9.下列语句序列执行后,r 的值是( ?)。
char ch='8'; int r=10;
switch( ch+1 )
{ case '7': r=r+3;
case '8': r=r+5;
case '9': r=r+6; break;
default: ;
}
A) 13 B) 15 C) 16 D) 10

 

 

20.对于一个三位的正整数 n,取出它的十位数字k(k为整型)的表达式是(D? )。
A) k = n / 10 % 10 B) k = ( n - n / 100 * 100 )%10
C) k = n % 10 D) k = n / 10

 

28.选择排序的思想是,将数据序列划分为两个子列,一个子列是排好序的,另一个是尚未排序的。现若想将数据序列由大到小排序,则每次放到有序子列尾部位置的元素,应从无序序列中选择( )。
A)最大的 B)最小的 C)任意的 D)头上的

 

 

 

29.已知int a[11]={12,18,24,35,47,50,62,83,90,115,134};使用对分查找法查找值为90的元素时, 查找成功所进行的比较次数是( )。

 

 

5.面向对象程序设计方法最重要的特性是继承、封装、________和多态。

 

8.数组、堆栈、___队列_____和链表都是线性数据结构。?

 

1.      Java中的的字符使用的是 16 位的Unicode 编码。

 

 

 

 

 

/*****************

for的循环体中是可以为空的

*****************/

12.for 语句中的循环体不能是空的。              


23.Java的源代码中定义几个类,编译结果就生成几个以.class为后缀的字节码文件。(√)
30.System类不能实例化,即不能创建System类的对象。(√)
1. abstract不能与final并列修饰同一个类

5、容器Panel和Applet缺省使用的布局编辑策略是(    B     )
A、BorderLayout B、FlowLayout C、GridLayout D、CardLayout

11、编译运行以下程序后,关于输出结果的说明正确的是 (   C     )
 public class Conditional{
  public static void main(String args[ ]){
   int x=4;
   System.out.println(“value is“+ ((x>4) ? 99.9 : 9));
}
}
A、输出结果为:value  is  99.99  B、输出结果为:value  is  9
C、输出结果为:value  is  9.0   D、编译错误


18、关于以下程序段,正确的说法是(     C      )
1.  String  s1=”abc”+”def”;
2.   String  s2=new  String(s1);
3.       if(s1= =s2)
4.     System.out.println(“= = succeeded”);
5.       if (s1.equals(s2))
6.     System.out.println(“.equals()  succeeded”);
A、行4与行6都将执行  B、行4执行,行6不执行
C、行6执行,行4不执行  C、行4、行6都不执行

 


/**************
查资料去
**************/
5.Java的屏幕坐标是以像素为单位,容器的左下角被确定为坐标的起点。(×?)

18.创建Vector对象时构造函数给定的是其中可以包容的元素个数,使用中应注意不能超越这个数值。(×?)

25.Java  Applet只能在图形界面下工作。(×?)

9、以下代码段执行后的输出结果为(     B   )
 int  x=3; int  y=10;
 System.out.println(y%x);
A、0    B、1    C、2     D、3

 

21、通过调用 new  List(10,false)创建一个列表,关于该列表的几个说法哪项是错误的。(             )
A、该列表不支持复选     B、该列表有10个选项
C、根据需要该列表可能有垂直滚动条 D、该列表支持10个可见选项


23、以下代码完成画线功能,指出所画线的颜色( c/d  )
 1.g.setColor(Color.red.green.yello.cyan);
 2.g.drawLine(0,0,100,100);
A、red   B、green    C、yello    D、cyan

 

 

 

 

/**************
需要注意的是数组没有length()方法,数组有length属性
**************/
16.使用方法length( )可以获得字符串或数组的长度。(×)


/**************
需要知道的是,该例子中所使用的x都是一个x变量。
**************/
14.关于以下程序代码的说明正确的是(     4     )
1. class  HasStatic{
2.     private  static  int  x=100;
3.     public  static  void  main(String  args[  ]){
4.         HasStatic  hs1=new  HasStatic(  );
5.         hs1.x++;
6.         HasStatic  hs2=new  HasStatic(  );
7.         hs2.x++;
8.         hs1=new  HasStatic( );
9.         hs1.x++;
1.  HasStatic.x- -;
10.       System.out.println(“x=”+x);
11.     }
12. }

1. 5行不能通过编译,因为引用了私有静态变量
2. 10行不能通过编译,因为x是私有静态变量
3.  程序通过编译,输出结果为:x=103
3. 程序通过编译,输出结果为:x=102


/***************
需要知道的是,当类加载时所有的静态初始化块都会先初始化。
***************/
13、关于以下application的说明,正确的是(  c      )
1.  class   StaticStuff
2.  {
3. static  int  x=10;
4. static  { x+=5;}
5. public  static  void  main(String  args[ ])
6. {
7.      System.out.println(“x=” + x);
8. }
9. static  { x/=3;}
10. }
A. 4行与9行不能通过编译,因为缺少方法名和返回类型
B. 9行不能通过编译,因为只能有一个静态初始化器
C. 编译通过,执行结果为:x=5
D. 编译通过,执行结果为:x=3


/*************************
需要注意到是当要重写父类的方法时,访问控制级别应该是相同的,可以变的是:
返回类型、参数各数|类型、抛的异常类
*************************/
17、类Test1、Test2定义如下:
1. public class  Test1
2.{ public  float  aMethod(float a,float b) throws
3.  IOException {      }
1. }
2. public  class  Test2  extends  Test1{
6.
 7.}
 将以下哪种方法插入行4是不合法的。(     1  )
1. float  aMethod(float  a,float  b){ }
2. public  int  aMethod(int a,int b)throws  Exception{ }
3. public  float  aMethod(float  p,float q){ }
4. public  int  aMethod(int a,int  b)throws IOException{ }
实例代码:
class  Test1{ 
 public  float  aMethod(float a,float b)throws IOException{
  return a;
 }
}

class  Test2  extends  Test1{
 float  aMethod(float a,float b){
  return a;
 }
/*
 public  int  aMethod(int a,int  b)throws Exception{ 
  return a;
 } 
*/
}

/*****************
需注意的是:MyListener继承了MouseAdapter类,就是鼠标适配器类,所以他可以不用实现所有鼠标事件。
*****************/
19、以下说法哪项是正确的(    1     )
 1.class  MyListener
 2.extends  MouseAdapter  implements  MouseListener{
1. public void mouseEntered(MouseEvent  mev)
2.   { System.out.println("Mouse  entered.");  }
3.  }
1. 以上代码可通过编译
2. 不能通过编译,因为没有实现MouseListener接口中的所有方法
3. 不能通过编译,因为类头定义不能分行
能通过编译,若组件用该类作为Mouse的监听者并且接收了mouse-exited事


/*********************
需要注意的是,Parent抽像类没有实现接口中的方法,可以用其子类实现该接口,
还有就是接口中的方法随然没有声名为public的,当编译接口时他会把所有的方法都改成public的,所以Child的方法缺少public会出问题。
*********************/
8、interface  MyInterface{
  void  method1();
 }
 abstract  class  Parent  implements  MyInterface{
}
class  Child  extends  Parent{
  public void  method1() {                 √
   System.out.println(“I  am  implemented  now!”);
  }
}

/********************
需要注意的:当使用try/cathc时,异常类型需从小到大,不应该先抛大的异常Exception在抛IOException
********************/
9、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());
  }*/ 
 }

/***********************
创建线程对象时,方法不能是静态的,下面是把他放到静太初始化块里了,
***********************/
10、public  class  AmIWrong  implements  Runnable {
     static{
  try{
  AmIWrong aw = new AmIWrong();
  Thread  mt=Thread(aw);
  mt.start();
  }catch(Exception e){
  System.out.println(e.toString());
  }
}
  void  run(){
   System.out.println(“I am alive now”);
  }
 }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值