当前位置:编程学习 > JAVA >>

java笔试02

此试题为北京南天软件java工程师面试题(部分)

一、单项选择

(1)下列关于构造方法的叙述中,错误的是(C)

A、java语言规定构造方法名与类名必须相同

B、java语言规定构造方法没有返回值,但不用void声明

C、java语言规定构造方法不可以重载

D、java语言规定构造方法只能通过new自动调用

(2)下列哪个类的声明是正确的(D)

A、abstract  final  class HI()

B、abstract  private  move(){}

C、protected  private  number;

D、public  abstract  class  Car{}

(3)关于被私有访问控制符private修饰的成员变量,以下说法正确的是(C)

A、可以被三种类所引用:该类本身、与它同一个包中的其他类、在其他包中的该类的子类

B、可以被两种类访问和引用:该类本身、该类的所有子类

C、只能被该类自身所访问和修改

D、只能被同一个包中的类访问

(4)以下声明合法的是(B)

A、default  String  s;

B、public  final  static  native  int  w()

C、abstract  double  d;

D、abstract  final  double  hyperbolicCosine()

(5)所有Exception的基类是(C)

A、IOException

B、Error

C、Throwable

D、RuntimeException

(6)下列关于for循环和while循环的说法中哪个是正确的(?)//有说A正确也有说D正确,不解?

A、while循环能实现的操作,for循环也都能实现

B、while循环判断条件一般是程序结果,for循环判断条件一般是非程序结果

C、两种循环任何时候都可替换

D、两种循环结构中都必须有循环体,循环体不能为空

(7)类Test1定义如下,将以下哪种方法插入行3是不合法的(B)

[java]  1、public class Test1 { 
2、    public float aMethod(float a,float b){}; 
3、   
4、} 

1、public class Test1 {
2、   public float aMethod(float a,float b){};
3、 
4、}A、public  float  aMethod(float  a,float  b,float  c){}

B、public  float  aMethod(float  c,float  d){}

C、public  int  aMethod(int  a,int  b){}

D、private  float  aMethod(int  a,int  b,int  c){}

(8)阅读以下代码输出结果为(C)

[java]  public class T { 
    public static void main(String[] args) { 
        String s; 
        System.out.println("s="+s); 
    } 

public class T {
 public static void main(String[] args) {
  String s;
  System.out.println("s="+s);
 }
}A、代码得到编译,并输出"s="

B、代码得到编译,并输出"s=null"

C、由于String  s没有初始化,代码不能编译通过

D、代码得到编译,但捕获到NullPointException异常

(9)编译运行以下程序后,关于输出结果的说明正确的是(C)//考察类型转换,低精度要向高精度转换

[java] public class T { 
    public static void main(String[] args) { 
        int x = 4; 
        System.out.println("value is "+((x>4)?99.9:9)); 
    } 

public class T {
 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、编译错误

(10)以下程序的运行结果为(C)

[java]  public class T { 
    public static void main(String[] args) { 
        int c = 2; 
        System.out.print(c); 
        System.out.print(c++); 
        System.out.print(c); 
    } 

public class T {
 public static void main(String[] args) {
  int c = 2;
  System.out.print(c);
  System.out.print(c++);
  System.out.print(c);
 }
}A、222   B、233

C、223  D、344

三、写出以下程序的运行结果

1、写出以下程序的运行结果

[java]  public class T { 
    public static void changeStr(String str){ 
        str = "welcome"; 
    } 
    public static void main(String[] args) { 
        String str = "1234"; 
        changeStr(str); 
        System.out.println(str); 
    } 

public class T {
 public static void changeStr(String str){
  str = "welcome";
 }
 public static void main(String[] args) {
  String str = "1234";
  changeStr(str);
  System.out.println(str);
 }
}答:运行结果为1234。String是不可变字符串

2、写出以下程序的运行结果

[java]  class First{ 
    public First(){ 
        aMethod(); 
    } 
    public void aMethod(){ 
        System.out.println("in First class"); 
    } 

public class Second extends First{ 
    public void aMethod(){ 
        System.out.println("in Second class"); 
    } 
    public static void main(String[] args) { 
        // TODO Auto-generated method stub  
        new Second(); 
    } 

class First{
 public First(){
  aMethod();
 }
 public void aMethod(){
  System.out.println("in First class");
 }
}
public class Second extends First{
 public void aMethod(){
  System.out.println("in Second class");
 }
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  new Second();
 }
}答:运行结果为in  Second  class

3、写出以下程序的运行结果

[java] public class T { 
    static boolean foo(char c){ 
        System.out.print(c); 
        return true; 
    } 
    public static void main(String[] args) { 
        int i = 0; 
        for(foo('a');foo('b')&&(i<2);foo('c')){ 
            i++; 
            foo('d'); 
        } 
    } 

public class T {
 static boolean foo(char c

补充:软件开发 , Java ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,