失效链接处理 |
Java笔试题总结(附答案) PDF 下载
本站整理下载:
提取码:4wct
相关截图:
主要内容:
选择题
1.哪一个标识符是不符合java语言规范的? B
A. $persons B. *point C. this D. _endline
2. —个类如果要定义其成员变量只能被同一个包内访问,那么我们应该使用哪一个修饰符?A
A. protected B. public C. no modifer D. private
3.下面的哪一个关键字是用来进行对象交互访问锁的,并且不允许其他对象访问的?A
A. transient B. serialize C. synchronized D. static
4.程序段:
public class Foo {
public void main (String [] args) {
System.out.println(“Hello World. ”);
}
}
运行结果会是如下的哪一个?
A. An exception is thrown B. The code does no compile
C. Hello World. w Is printed to the terminal. D. The program exits without print
5.给出下面的程序段:
if (x>0){
System.out.println(“first”);
}else if (x>-3){
System.out.println(“second”);
}else{
System.out.println(“third”);
}
当x取何值的时候,打印字符串是”second”? A
A. x <= 0 & x > -3 B. x > -3 C. x <= —3 D. x > 0
8.下面的程序段,执行结果将是哪一个呢?
class ValHold {public Int i = 10;}
public class ObParn{
public void amethod(){
ValHold v = new ValHold();
another(v);
System.out.print(v.i);
}
public void another(ValHold v){
v.i = 20;
ValHold vh = new ValHold();
v = vh;
System.out.print(v.i);
}
public static void main(String[] args) {
ObParm o = new ObParm();
o.amethod();
)
}
A. 10 10 B.10 20 C.20 10 D.20 20
9.下面程序代码,如果Hello.txt文件不存在,执行的结果将是什么?
import java.io.*;
public class Mine{
public static void main(String[] args){
Mine m = new Mine();
System.out.print(m.amethod());
}
public int amethod(){
try {
FilelInputStream dis = new FileInputStream(Hello.txt);
}catch(FileNotFoundException fne){
System.out.print("No found");
return -1;
}finally{
System.out.println("Finally");
}
return 0;
}
}
A.No found -1 B.No found Finally -1 C.-1 D.没有显示结果
1O.下面程序段,执行的结果是?
class Base {
Rese(){
System.out.println("Base");
}
}
class Sub extends Base{
Sub(){
System.out.println("Sub");
}
}
public class Maker{
public static void main(String[] args){
Base b = new BaseO ;
Sub s = (Sub) b;
}
}
A.compile has errors. B.compile has no error but throw exception at runtime C. print Base D. print Base and Sub.
|