全国招聘JAVA笔试精选模拟题

下列语句中错误的是()。

A.“int *p=new int (10);”

B.“int *p=new int [10];”

C.“int *p=new int ;”

D.“int *p=new int (10)(0);”


参考答案:D


下列语句中错误的是( )。

A.int a[][]=new int[2][];

B.int a[][]=new int[][];

C.int a[][]=new int[2][3];

D.int[][] a=new int[3][2];


正确答案:B
解析:在Java中,定义二维数组的形式不是唯一的,既可以像选项C、D那样,在使用new运算符为数组分配内存空间时指出每一维的容量;又可以像选项A那样,在为数组分配内存空间时只指定第一维(最左边)的容量。


下列数组定义及赋值,错误的是( )。

A.int a[]={1,2,3,4,5};

B.int intArray[];

C.int Array=new int[3]; int Array[1]=1; int Array[2]=2; int Array[3]=3;

D.int a[][]=new int[2][]; a[0]=new int[3]; a[1]=new int[3];


正确答案:C
解析:一维数组的定义方法为:type arrayName[];,其中类型type可以为Java中任意数据类型,所以选项B是正确的。对数组元素赋值,可以在定义数组的同时进行初始化,所以选项A是正确的。数组下标从0开始,所以选项C是错误的。对多维数组赋值,从最高维开始,分别为每一维分配空间,所以选项D是正确的。


如下两个源程序文件,分别编译后,运行Example.class文件,运行结果为______。

AB.java文件代码如下;

package test;

public class AB

{

int a=60;

public void show()

{

System.out.println(”a=”+a);

}

Example.java文件代码如下:

import test.AB;

class Example

{

public static void main(String args[])

{

AB bj=new AB();

obj.show();

}

}


正确答案:a=60
a=60


Given:Which code, inserted at line 15, allows the class Sprite to compile?()

A.Foo { public int bar() { return 1; }

B.new Foo { public int bar() { return 1; }

C.new Foo() { public int bar() { return 1; }

D.new class Foo { public int bar() { return 1; }


参考答案:C


下列哪个类是RuntimeException类的子类( )A.ArrayIndexOutOfBoundsException B.ErrorC.Throwable; D.Exception

有内部类定义如下:public class OutApublic class InnerB则在其它类中,创建内部类InnerB对象的语句是( )A.InnerB ab=new InnerB();B.OutA.InnerB ab=new OutA.InnerB();C.OutA.InnerB ab=new OutA().new InnerB();D.InnerB ab=new OutA.InnerB();

在类中定义有两个方法class MyClassdouble addTwoData(int a,int b)return a+b;int addTwoData(int a,int b)return a+b;下列说法正确的是( )A.addTwoData()方法重载B.编译错误C.addTwoData()方法改写D.以上说法都不正确( )

下列哪个类能为每个使用该变量的线程提供独立的变量副本( )A.Thread B. ThreadFactory C.ThreadInfo D.ThreadLocal

从字符串JAVA中获取子目V所在的位置(位置结果是2),你选择用哪个方法 ( )A.indexOf(s,v); B.charAt(2); C.s.indexOf(v); D. mid(2,s);

下列运算符合法的?(A )A.& B.:= C.if D. 7、B/S架构的B最确切的是指什么 ( )A.和服务端一同提供配套的客户端软件 B.基础软件环境C.网页浏览器 D. Firefox软件

RCP中都是使用下列哪项技术来扩展功能的,比如菜单、透视图、编辑器等。( )A 插件 B.扩展点 C.工作台 D.工作区

下列正确的是:( B )A.Java程序经编译后会产生DLLB.Java程序经编译后会产生byte codeC.Java程序经编译后会产生machine codeD.以上都不正确

 以下哪个不是Collection的子接口?( )A.List B.SortedSet C.Set D.Map11、JSP中,不可以在多个页面中一直保持数据的对象是 ( )A.request B.cookie C.application D.session

 下面语句请选择正确的输出( )System.out.println(4 | 3);A. 1 B.0 C. 6 D.7

 、编译运行如下代码,输出是( )public class myprogpublic static void main(String argv)System.out.println(argv2) ;A.null B. myprog C.0D.Exception raised: java.lang.ArrayIndexOutOfBoundsException: 2

 编译运行如下代码,将会( )public class MyClasspublic static void main(String argv)MyClass h = new MyClass ();protected MyClass ()for(int i =0; i 10; i +)System.out.println(i);A.输出0到10B.Run time error: Constructors cannot be declared protectedC.Compilation error: Constructors cannot be declared protectedD.输出0到9

 下列哪个会告诉jvm执行垃圾回收 ( )A.System.free(); B. System.out.gc();C.System.gc(); D.System.setGarbageCollection();

 下列哪个类的声明是正确的? ( )A.abstract private move() B. abstract final class HIC.protected private number; D.public abstract class Car

使用VC6打开考生文件夹下的工程test15_3。此工程包含一个test15_3.cpp,其中定义了类Time和Timex,Timex公有继承Time,但定义并不完整。请按要求完成下列操作,将程序补充完整。

(1)完成类Time构造函数的定义,将数据成员hours和minutes分别初始化为参数new_hours和new_minutes的值。请在注释“//**1**”之后添加适当的语句。

(2)完成类Timex的构造函数的定义,注意参数的传递。请在注释“//**2**”之后添加适当的语句。

(3)请按时间格式“hour:minute”和“hour:minute:second”分别输出对象time1和time2所表示的时间,注意必须使用已经定义的成员函数。请在注释“//**3**”之后添加适当的语句。

输出结果如下:

20:30

10:45:34

注意:除在指定的位置添加语句外,请不要改动程序中的其他语句。

源程序文件test15_3.cpp清单如下:

include<iostream.h>

class Time

{

public:

Time(int new hours,int new_minutes)

{

// ** 1 **

}

int get_hours();

int get_minutes();

protected:

int hours,minutes;

};

int Time::get_hours()

{

return hours;

}

int Time::get_minutes()

{

return minutes;

}

class Timex:public Time

{

public:

Timex(int new hours,int new_minutes,int new_seconds);

int get_seconds();

protected:

int seconds;

};

// ** 2 **

{

seconds=new_seconds;

}

int Timex::get_seconds()

{

return seconds;

}

void main()

{

Time time1(20,30);

Timex time2(10,45,34);

// ** 3 **

}


正确答案:(1) hours=new_hours; minutes=new_minutes; (2) Timex::Timex(int new_hoursint new_minutes int new_seconds):Time(new_hoursnew_minutes) (3) couttime1.get_hours()":"time1.get_minutes()end1; couttime2.get_hours()":"time2.get_minutes()":"time2.get_seconds()endl;
(1) hours=new_hours; minutes=new_minutes; (2) Timex::Timex(int new_hours,int new_minutes, int new_seconds):Time(new_hours,new_minutes) (3) couttime1.get_hours()":"time1.get_minutes()end1; couttime2.get_hours()":"time2.get_minutes()":"time2.get_seconds()endl; 解析:本题主要考查考生对于类和派生类构造函数的定义以及成员函数的使用,注意(2)中派生类构造函数中必须包括向基类传递参数的调用,应该使用参数列表完成这一操作。


本题定义了一个求两个数的最大值的方法max,并调用该方法计算67和23的最大值。 public class javal{ public static void main(String[]args){ javal temp=new javal; int res=max(67,23); System.out.println("res="+res); } static int maX( ){ int maxNum; if(a>b) ; else maxNum=b; ; } }


正确答案:
第1处:int a,int b
第2处:maxNum=a
第3处:return maxNum
【解析】第1处定义max方法中的两个整型形参;第2处将两者中较大的赋给maxNum;第3处返回最大值。


设A为已定义的类名,则下列声明A类的对象a的语句中正确的是( )。

A.public A a=new A

B.public A a=A

C.A a=new class;

D.a A;


正确答案:A
A。【解析】对象的生成包括声明、实例化和初始化3个方面的内容,一般格式是先定义一个对象变量,再用关键字new生成一个对象,并为该对象变量赋值。


设有类定义如下:

class Base{

public Base(int i){}

}

public class MyOver extends Base{

public static void main(String arg[]){

MyOver m = new MyOver(10);

}

MyOver(int i){

super(i);

}

MyOver(String s, int i){

this(i);

//Here

}

}

以下哪条语句可以安排在//Here处 ?

A.MyOver m = new MyOver();

B.super();

C.this("Hello",10);

D.Base b = new Base(10);


正确答案:D


假定AB为一个类,则执行“AB *p=new AB(1,2);”语句时共调用该类构造函数的次数为()

  • A、 0
  • B、 1
  • C、 2
  • D、 3

正确答案:B

更多 “全国招聘JAVA笔试精选模拟题” 相关考题

1. class SuperFoo {  2. SuperFoo doStuff(int x) {  3. return new SuperFoo(); 4. }  5. }  6.  7. class Foo extends SuperFoo {  8. //insert code here  9. }   下面哪三项分别插入到第8行,可以编译?()

  • A、int doStuff() { return 42; }
  • B、int doStuff(int x) { return 42; }
  • C、Foo doStuff(int x) { return new Foo(); }
  • D、SuperFoo doStuff(int x) { return new Foo(); }

正确答案:A,C,D


以下的数组定义语句中,不正确的是()

  • A、 int[] a=new int[5]{1,2,3,4,5};
  • B、 int[,] a=new int[3][4];
  • C、 int[][] a=new int[3][];
  • D、 int[] a={1,2,3,4,5};

正确答案:B


假定AB为一个类,则执行 “AB *s=new AB(a,5);”语句时得到的一个动态对象为()

  • A、 s
  • B、 s->a
  • C、 s.a
  • D、 *s

正确答案:D


单选题
以下的数组定义语句中,不正确的是()
A

 int[] a=new int[5]{1,2,3,4,5};

B

 int[,] a=new int[3][4];

C

 int[][] a=new int[3][];

D

 int[] a={1,2,3,4,5};


正确答案: C
解析: 暂无解析


假定AB为一个类,则执行 “AB *px=new AB[n];”语句时调用该类无参构造函数的次数为()

  • A、 n
  • B、 n-1
  • C、 1
  • D、 0

正确答案:A


现有:  1.class SuperFoo{  2.SuperFoo doStuff (int x)  {      3.return new SuperFoo();      4.    }      5.  }      6.  7. class Foo extends SuperFoo  {     8.    //insert code here     9.  }  和四个声明:   Foo doStuff (int x)  {  return new Foo();  }  Foo doStuff (int x)  {  return new SuperFoo();  }      SuperFoo doStuff(int x)  {  return new Foo();  }  SuperFoo doStuff(int y)  {  return new SuperFoo();  }    分别插入到第8行,有几个可以通过编泽?()    

  • A、 1
  • B、 2
  • C、 3
  • D、 4

正确答案:D


以下建立动态存储的语句正确的是()

  • A、int p=new int;
  • B、int p=new(10);
  • C、int *p(10);
  • D、int *p=new int(10);

正确答案:D


多选题
下面哪个语句正确地声明一个整型的二维数组?()
A

int a[ ][ ] = new int[][];    

B

int a[10][10] = new int[][];    

C

int a[ ][ ] = new int[10][10];    

D

int [ ][ ]a = new int[10][10];    

E

int [ ]a[ ] = new int[10][10];


正确答案: C,D
解析: 暂无解析


下列的数组定义语句,不正确的是()。

  • A、int a[]=new int[5]{1,2,3,4,5}
  • B、int[,]a=new inta[3][4]
  • C、int[][]a=new int[3][];
  • D、int[]a={1,2,3,4};

正确答案:D


单选题
下列建立动态存储的语句正确的是()
A

int p=new int[];

B

int p=new [10];

C

int *p=new int[10];

D

int *p[10]=new int;


正确答案: C
解析: 暂无解析