java基础试题四.docx

上传人:b****5 文档编号:8330645 上传时间:2023-01-30 格式:DOCX 页数:10 大小:16.90KB
下载 相关 举报
java基础试题四.docx_第1页
第1页 / 共10页
java基础试题四.docx_第2页
第2页 / 共10页
java基础试题四.docx_第3页
第3页 / 共10页
java基础试题四.docx_第4页
第4页 / 共10页
java基础试题四.docx_第5页
第5页 / 共10页
点击查看更多>>
下载资源
资源描述

java基础试题四.docx

《java基础试题四.docx》由会员分享,可在线阅读,更多相关《java基础试题四.docx(10页珍藏版)》请在冰豆网上搜索。

java基础试题四.docx

java基础试题四

1下面的语句哪一行在编译时没有警告和编译错误(e)

a)     floatf=1.3;

b)     charc="a";

c)     byteb=257;

d)     booleanb=null;

e)     inti=10;

2下面的代码编译后会出现什么问题(a)

publicclassMyClass{

   publicstaticvoidmain(Stringarguments[]){

        amethod(arguments);//无法从静态上下文中引用非静态方法

}

   publicvoidamethod(String[]arguments){

        System.out.println(arguments);

        System.out.println(arguments[1]);

   }

}

a)     错误,不能静态引用amethod方法

b)     错误,main方法不正确

c)     错误,数组必须包含参数

d)     Amethod必须声明为String类型

3下面的哪一组代码会出现编译错误(a)

a)     importjava.awt.*;//如果有包的时候(导入aw包是应该放在package包中)

packageMypackage;

classMyclass{}

b)     packageMyPackage;

importjava.awt.*;

classMyClass{}

c)     /*Thisisacomment*/

 

packageMyPackage;

importjava.awt.*;

classMyClass{}

4)byte类型的大小是(a)

a)-128~ 127

b)-28-1~28

c)-255~256

d)不同的操作系统Java虚拟机分配不同的大小

5)下面的代码在输入下面的命令行后会输出什么内容(d)

命令行:

javamyproggoodmorning

代码:

publicclassmyprog{

   publicstaticvoidmain(Stringargv[])

   {

        System.out.println(argv[2]);

   }

}

a)myprog

b)good

c)morning

d)Exceptionraised:

"java.lang.ArrayIndexOutOfBoundsException:

2"

6)下面哪个不是Java的关键字或者保留字(b)

a)if

b)then

c)goto

d)while

e)case

7)下面哪些是合法的标志符(多选)(b,c,e,d_)

a)2variable

b)variable2

c)_whatavariable

d)_3_

e)$anothervar

e)#myvar

8)试图编译运行下面的代码会发生什么情况

publicclassMyClass{(D)

 staticinti;

 publicstaticvoidmain(Stringargv[]){

 System.out.println(i);

 }

}

a)错误,变量i没有被初始化

b)null

c)1

d)0

9)试图编译运行下面的代码会发生什么情况(C)

publicclassQ{

 publicstaticvoidmain(Stringargv[]){

 intanar[]=newint[]{1,2,3};

 System.out.println(anar[1]);

 }

}

a)1

b)Erroranar被引用前没有初始化

c)2

d)Error:

数组大小没有定义

10)试图编译运行下面的代码会发生什么情况(C)

publicclassQ{

 publicstaticvoidmain(Stringargv[]){

 intanar[]=newint[5];

 System.out.println(anar[0]);

 }

}

a)Error:

anarisreferencedbeforeitisinitialized

b)null

c)0

d)5

11)试图编译运行下面的代码会发生什么情况(C)

abstractclassMineBase{

 abstractvoidamethod();

 staticinti;

}

publicclassMineextendsMineBase{

 publicstaticvoidmain(Stringargv[]){

 int[]ar=newint[5];

 for(i=0;i

 System.out.println(ar[i]);

 }

}

a)5个0的序列会被输出

b)Error:

ar在使用前要初始化

c)ErrorMine必须被声明为abstract

d)Error数组越界

12)试图编译运行下面的代码会输出什么样的结果(c)

inti=1;

 switch(i){

 case0:

 System.out.println("zero");

 break;

 case1:

 System.out.println("one");

 case2:

 System.out.println("two");

 default:

 System.out.println("default");

 }

a)one

b)one,default

c)one,two,default

d)default

13)试图编译运行下面的代码会输出什么样的结果(b)

inti=9;

switch(i){

 default:

 System.out.println("default");

 case0:

 System.out.println("zero");

 break;

 case1:

 System.out.println("one");

 case2:

 System.out.println("two");

}

a)default

b)default,zero

c)errordefault没有定义

d)无输出

14)下面的哪些组代码没有编译错误(多选)(b,C)

a)

inti=0;

if(i){

 System.out.println("Hello");

 }

b)

booleanb=true;

booleanb2=true;

if(b==b2){

 System.out.println("Sotrue");

 }

c)

inti=1;

intj=2;

if(i==1||j==2)

 System.out.println("OK");

d)

inti=1;

intj=2;

if(i==1&|j==2)

 

 System.out.println("OK");

15如果在当前目录下不存在Hello.txt文件,试图编译和运行下面代码会输出什么(c)

importjava.io.*;

publicclassMine{

   publicstaticvoidmain(Stringargv[]){

        Minem=newMine();

        System.out.println(m.amethod());

   }

   publicintamethod(){

        try{

           FileInputStreamdis=newFileInputStream("Hello.txt");

        }catch(FileNotFoundExceptionfne){

           System.out.println("Nosuchfilefound");

           return-1;

        }catch(IOExceptionioe){

        }finally{

           System.out.println("Doingfinally");

        }

 

        return0;

   }

 

}

a)Nosuchfilefound

b)Nosuchfilefound,-1

c)Nosuchfilefound,Doingfinally,-1//finally语句回执行在return之前:

d)0

16)在下面的注释处插入哪些部分代码是合法的(多选)

classBase{

 publicvoidamethod(inti){}

}

 

publicclassScopeextendsBase{

 publicstaticvoidmain(Stringargv[]){

 }

 //在这里定义一个方法

}

a)voidamethod(inti)throwsException{}

b)voidamethod(longi)throwsException{}

c)voidamethod(longi){}

d)publicvoidamethod(inti)throwsException{}

17)下面哪行代码输出-4.0(C)

a)System.out.println(Math.floor(-4.7));//返回<=参数的最大整数

b)System.out.println(Math.round(-4.7));//返回最接近参数的long型值

c)System.out.println(Math.ceil(-4.7));//返回>=参数的最小整数

d)System.out.println(Math.min(-4.7));//返回参数中的最小值

18)如果运行下面的代码会输出什么内容

(2)

Strings=newString("Bicycle");

intiBegin=1;

chariEnd=3;

System.out.println(s.substring(iBegin,iEnd));//subString()是String的方法,在这里的用法是输出1~~~3位的字符

1)Bic

2)ic

3)icy

4)error:

没有匹配的方法substring(int,char)

19)给出下面的代码在注释部分放置什么样的代码会输出“Equal”(c)

publicclassEqTest{

         publicstaticvoidmain(Stringargv[]){

                   EqTeste=newEqTest();

       }

 

        EqTest(){

                   Strings="Java";

                   Strings2="java";

                   //placetesthere{

                            System.out.println("Equal");

                            }else

                            {

                            System.out.println("Notequal");

                   }

         }

}

a)if(s==s2)

b)if(s.equals(s2)

c)if(s.equalsIgnoreCase(s2))

d)if(s.noCaseMatch(s2))

20)给出下面的代码,怎样调用Base的构造方法会输出"baseconstructor"(c)

classBase{

   Base(inti){

        System.out.println("baseconstructor");

   }

   Base(){

   }

}

 

publicclassSupextendsBase{

   publicstaticvoidmain(Stringargv[]){

        Sups=newSup();

        //One

   }

   Sup()

   {

        //Two

   }

 

   publicvoidderived()

   {

        //Three

   }

}

a)//One后放置Base(10);

b)//One后放置super(10);

c)//Two后放置super(10);

d)//Three后放置super(10);

参考答案:

1-5eaaad

6-10bbcdedcc

11-15ccbbcc

16-20bccbcd

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 表格模板 > 合同协议

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1