java考试试卷及答案

别妄想泡我
848次浏览
2021年02月16日 02:45
最佳经验
本文由作者推荐

蜜蜂酿蜜-

2021年2月16日发(作者:驭风男孩)









































JA< /p>


V


A


考试试卷及答案



选择题




3


、在


Java



Applet


程序用户自定义的


Applet


子类中,一般需要重载父类的


(



D





)


方法


来完 成一些画




图操作。








A.




start()





















B.




stop()



C.




init()






















D.




paint()



3



Java


语言具有许多优 点和特点,下列选项中,哪个反映了


Java


程序并行机制的特 点?


B







A)


安全性






B)


多线程






C)


跨平台






D)


可移植




4


、下列哪个类声明是正确的?


D







A)abstract final class HI{·


·


·




B)abstract private move(){·


·


·


}







C)protected private number;









D)public abstract class Car{·


·


·


}



6


、在


Ja va


语言中,下列哪些语句关于内存回收的说明是正确的


? B



A


.程序员必须创建一个线程来释放 内存;





B


.内存回收程序负责释放无用内存





C


.内存 回收程序允许程序员直接释放内存





D


.内存回收程序可以在指定的时间释放内存对象





10


、下列


Object


类中的方法,哪一项不是完全跟线 程有关:



A



A



String toString()




B



void notify()




C



void notifyAll()




D



void wait()



11


、给出下面代码:


C



public class Person{








static int arr[] = new int[10];







public static void main(String a[])







{










n(arr[1]);








}




}




下列说法中正确的是?





A


.编译时将产生错误;





B


.编译时正确,运行时将产生错误;





C




输出零;





D




输出空。




12


、字符串是


Java


已定义的类型 ,关于它的构造函数,下面说法不正确的是:



A



String(char[] value, int offset, int count)




B



String(int[] codePoints,int offset,



int count)




C



String(String original)



D



String(StringBuffer buffer)



13


、下列说法中正确的是:



C



A


.导入包会影响程序的性能




B


.包存储在类库中




C


.包是类的容器

< br>D


.上述说法都不对




14


、下列不是


String


类的常用方法是:


C


B




A



boolean equals(String str)



B



int compareTo(String str)



C



int SetindexOf(String str)



D



int lastIndexOf(String str)



17


、表达式:


(x>y) ? (z>w) ?x:z:w



(其中


x =5,y=9,z=1,w=9


)的值为:


D



A



5




















B



8



C



1




















D



9



1



mai n


方法是


Java



Application


程序执行的入口点,关于


ma in


方法的方法头以下哪项是


合法的(





B





)?




A



public



static



void



main







B



public



static



void




main




String



args[]





C



public static int



main



String



[] arg





D



public



void



main



String



arg[]





5


、欲构造


ArrayList


类的一个实例 ,下列哪个方法是正确的





B



A




ArrayList myList=new Object()






B




ArrayList myList=new ArrayList()






C




myList= new Object()






D




myList= new ArrayList()





7


、哪个关键字可以对对象加互斥锁?



B



A



transient




B



synchronized




C



serialize




D



static




9


、下列叙述中,错误的是:



D



A


、父类不能替代子类




B


、子类能够替代父类




C


、子类继承父类




D


、父类包含子类





10


、下 列关于


Java


多线程并发控制机制的叙述中,错误的是:


BC



A



Java


中对共享数据操作的并发控制是采用加锁技术




B


、线程之间的交互, 提倡采用


suspend()/resume()


方法




C


、共享数据的访 问权限都必须定义为


private



D



Java


中没有提供检测与避免 死锁的专门机制,但应用程序员可以采用某些策略防止死锁


的发生




12


、下列哪一个方法不是


applet


程序的组成部分:


D



A



init()



















B



start()



C



stop()


















D



new()



15



Ja va


应用程序中,程序执行的总入口方法是:


B



A



start()















B



mai n()C



run()
















D



init()



16


、在


J ava


实现线程有多少种方法:


B



A



1















B



2



C



3















D



4


< /p>


18


、下列


Applet


类的方法中,在


Applet


的整个生命周期里至多只 执行一次的是:


A



A



init()
















B



start()



C



stop()















D



paint()



19


、启动一个线程所调用的方法是 :


C



A



run()















B



init()



C



start()













D



new()



判断题




1


.一个


Java

类可以有多个父类。




4



Java


小程序


A pplet


的主类的父类必须是类


Applet





5


break


语句可以用在循环和


switch


语句中。



< p>
6


.在


Java


中,异常


Exception


是指程序在编译和运行进出现的错误。




7


.可以用< /p>


new


来创建一个类的实例,即对象。




8



Jav a


使用


16


位的


Unicode


字符集,而不仅仅为


ASCII


字符集,因此


Java


字符是一个

< br>16


位的无符号整




数。




10


.子类的成员变量能与其父类的成员变量同名。




11



Ja va


类中不能存在同名的两个成员函数。




12



Ja va


语言是编译性语言。




16



final


方法 不能被覆盖。




20


.多数


I/O


方法在遇到错误是会抛出异常,因此在调 用这些方法时必须对异常进行处理。




2



abstract


是抽象修饰符,可以用来修饰类及其属性和方法。




4


.一个


Java Applet


源程序的主类能有多个父类。




6


.用


ja vac


编译


Java


源文件后得到代码 叫字节码。




7


.可以用类名调用实例方法。




9


.要想在类中实现多线程,类必须 继承


Thread


类。




11



Ja va


语言是平台无关的语言。




12


.在类的静态方法中可以访问该类的非静态数据成员。




13


< p>
Java


中方法调用时参数传递都是按值传递的,因此从方法退出时,参数 的值不会改变。




14


.声明为


final


的方法不能在子类中重载。




15


.在子类 中可以覆盖一个


private


方法。




19


.在方法定义中,所有可能发生 的异常都必须用


try{}catch(){}


捕捉并处理




1.


请写出输出结果




class change{





void changeint(int x){







x++;





}



public static void main(String args[]){







int a=2;









n(






//


请系统输出


Before changed:







change cxz=new change();







int(a);







n(







}



}



答案:




Before changed:



a=





2





After changed:



a=






3






a=



2.


下面程序运行的最终结果


i


是:


___2_____



public class Foo {







public static void main (String []args) {








int i = 1;




















int j = i++;











if ((i>++j) && (i++ ==j)) {









i +=j;







}






}



}



3


、阅读以下程序,请写出输出结果




import .*;



public class StrCompare



{









public static void main(String[] args)









{









String










str1 =









str2 =









n(eToIgnoreCase(str2));









n((str2));







n(IgnoreCase(str2));







}



}




:



0



False



True



4


、阅读以下程序,请写出输出第一行结果




public class abc







{













public static void main(String args[ ])













{





int i =3,j


















while (i>0){


















j=3;


















while (j>0){
















if (j<2)


















break;


















n(




















j--;


















}


















i--;


















}












}







}




:



j+and3



j+and3



j+and2



j+and2



j+and1



j+and1



5




import





.*;



public



class



abc



{










public



static



void



main(String args[ ])













{





AB



s = new



AB(


V


A.


















n(ng( ));













}



}



class




AB {





String




s1;





String




s2;





AB( String



str1 , String



str2 )





{



s1 = str1;



s2 = str2; }





public




String




toString( )





{ return



s1+s2;}



}




:



Hello!I love JA


V


A.



6


、阅读以下程序,请写出输出


c.x=

是多少




public class withstaticdata {



static int x;




int y;




public static void main(String[] args) {



withstaticdata a=new withstaticdata();



a.x=1;




n(a.x);withstaticdata b=new withstaticdata();



b.x=2;




n(b.x); n(a.x); withstaticdata c=new withstaticdata();



n(





}




:2



public class StaticFun {



static void incr(){






withstaticdata.x++



;



}



public static void main( String [] args )



{

蜜蜂酿蜜-


蜜蜂酿蜜-


蜜蜂酿蜜-


蜜蜂酿蜜-


蜜蜂酿蜜-


蜜蜂酿蜜-


蜜蜂酿蜜-


蜜蜂酿蜜-