sokaoti.com
全省北京上元思创科技有限公司招聘JAVA面试模拟题考试专题训练

有如下类定义:

class Test

{

public:

Test(){ a = 0; c = 0;} // ①

int f(int a)const{this->a = a;} // ②

static int g(){return a;} // ③

void h(int

B . {Test::b = b;}; // ④

private:

int a;

static int b;

const int c;

};

int Test::b = 0;

在标注号码的行中,能被正确编译的是

A . ①

B . ②

C . ③

D . ④


正确答案:C


下列函数的功能是【 】。include int Func(int a,int b) {if (a>b) return 1; else if

下列函数的功能是【 】。

include<iostream. h>

int Func(int a,int b)

{

if (a>b) return 1;

else if(a==b) return 0;

else return -1;

}


正确答案:比较两个整数a和b的大小若a>b则返回1若a等于b则返回0否则返回-1。
比较两个整数a和b的大小,若a>b则返回1,若a等于b,则返回0,否则返回-1。


下面函数的作用是【 】。

int index(int x,int a[],int n)

{

for(int i=0;i<n;i++)

{

if(a[i]==x)

return i;

}

return i;

}


正确答案:数组a中查找x若有则返回第一个x的下标若没有则返回n
数组a中查找x,若有则返回第一个x的下标,若没有则返回n 解析:函数的作用是通过变量数组,在数组中查找x,若找到则显示下标i。


有以下程序:includeusingnamespacestd;definePI3.14classPoint{private: intx,y;pub

有以下程序: #include <iostream> using namespace std; #define PI 3.14 class Point { private: int x,y; public: Point(int a,int b) { x=a; y=b; } int getx() { return x; } int gety() { return y; } }; class Circle : public Point { private: int r; public: Circle(int a,int b,int c):Point(a,b) { r=c; } int getr() { return r; } double area() { return PI*r*r; } }; int main() { Circle c1(5,7,10); cout<<cl.area()<<endl; return 0; } 程序执行后的输出结果是

A.314

B.157

C.78.5

D.153.86


正确答案:A
解析:本题考核派生类的定义和应用。本程序设计了一个点类Point,包含了横、纵两个坐标数据x和y,由它派生出了圆类Circle,并加入了新的数据成员,即一个半径r和一个求圆面积的函数成员area。在主函数main中,首先定义了一个圆Circle类的对象c1,并通过它的构造函数初始化其数据成员。由此可知,其半径r的值为10,所以其面积为PI*10*10=314,即对象c1的函数成员area的返回值为314。


有以下程序:includeint a=2;int f(int *a){return (*a) ++;}main(){ int s=0;{ int a=

有以下程序: #include <stdio.h> int a=2; int f(int *a) { return (*a) ++;} main() { int s=0; { int a=5; s+=f(&a); } s+=f(&a); printf("%d\n",s) } 执行后的输出结果是( )。

A.10

B.9

C.7

D.8


正确答案:C
解析:在一个函数内部定义的变量是内部变量,它只在本函数范围内有效,也就是说只有在本函数内才能使用这些变量。对于main函数中的{inta=5;s+=f(&a);},a只在花括号内有效。在函数之外定义的变量称为外部变量,外部变量是全局变量,它的有效范围是从定义该变量的位置开始到本源文件结束。程序开头的定义inta=2;使a成为全局变量,main函数中第二个s+=f(&a);语句中的a就是这个全局变量。


北京上元思创科技有限公司招聘JAVA面试真题1.请参看如下代码:class Demo protected int method1(int a, int b)return 0;请问下列选项中哪些方法可以在的Demo子类中编译通过?(多选)_(A)static protected int method1(int a, int b)return 0;(B)public short method1(int a, int b)return 0;(C)private int method1(int a, int b)return 0;(D)private int method1(int a, long b)return 0;(E)public int method1(int a, int b)return 0;2.try里有一个return语句,那么紧跟在这个try后的finally里的code会不会被执行,什么时候执行,在return前还是后?_(A)会在return前执行(B) 会在return后执行(C)不执行(D)不确定3.下面哪个方法不是java.io.InputStream的方法?(A)int read(byte )(B)void flush( )(C)void close( )(D)int available( )10.怎样能够让GC(Garbage Collection)强制回收一个对象?_(A)垃圾回收不能强制回收一个对象(B)调用System.gc( )(C) 调用System.gc( ),传入需要垃圾回收的对象引用(D)调用Runtime.gc( )(E)设置对象引用等于null11.请完成下面的代码:int success=connection( );if(success = -1)throw new TimeOutException( );其中TimeOutException不是一个RuntimeException,请问下面哪个代码放到上述的(1)处能使代码通过编译(假设是connection( )类的成员函数)(多选)_(A)public void method( )(B)public void method( ) throws Exception(C) public void method() throws TimeOutException(D) public void method() throw TimeOutException(E)public throw TimeOutException void method()12.下面有关线程的哪些叙述是正确的?(多选)_(A)一但一个线程被创建,他就立即开始运行。(B)使用start( )方法可以使一个线程成为可运行的,但是它不一定立即开始运行(C)使用start( )方法可以使一个线程立即开始运行(D)当一个线程因为抢先机制而停止运行,它被放在可运行的队列的按前面。(E)一个线程可能因为不同的原因停止(cease)并进入就绪状态13.以下关于和接口的描述正确的是(多选):_(A)接口可以继承接口(B)实体类能实现接口,而抽象类不能实现接口(C)实体类能继承接口(D)抽象类能继承实体类14.下面哪个属于的JDBC的类(A)java.sql.Connection(B)java.sql.Statement(C)java.sql.ResultSet(D)java.sql.DriverManager15.请参看如下代码Connection conn = null;Statement st = null;try conn = getConnection(); st = conn.createStatement(); st.executeUpdate(“update test set a = 1”); (1)catch(SQLException ex) (2)finally (3)请选择关闭statement合适的时机(请注意上述连接是通过连接池获取的):_(A)不需要关闭statement,关闭Connection时会自动关闭(B)在(1)处关闭statement(C)在(2)处关闭statement(D)在(3)处关闭statement16.请问java.sql.statement 和java.sql.PreparedStatement中的executeUpdate()方法在执行update语句时返回值是什么?(A)没有返回值(B)返回值为1或0;1表示成功,2表示失败(C)返回值为true或false;true表示成功,false表示失败 (D)返回值为=0的整数,表示执行SQL影响的记录数17.在下列的servlet函数中,哪些函数是每次HTTP请求所可能调用的方法?多选_(A)Servlet构造函数(B)init( )方法(C)service()方法(D)doGet()方法(E)doPost()方法18.请写出执行Dome将会打印出的结果:_public class A public void m() System.out.println(“A”);class B extends A public void m() System.out.println(“B”);public class Demo public static void main(String args) A a1 = new A(); a1.m(); A a2 = new A(); a2.m(); B b1 = new B(); b1.m(); B b2 = new B(); b2.m();(A) (B) (C) (D)A A A AB B A AA B B AB B B B19.以下程序输出结果是怎样的:_public class testStatic int i;Public static void main( String args) for ( int j=0 ;j5 ; j+) System.out.println( i ); i+;A) 编译异常,变量未初始化B) 输出0后,程序异常退出C) 12345D) 0123420 、 以下关于数据库中主键和外键的描述,哪些是正确的(多选):_A) 主键用于保证数据唯一性,外键保证数据完整性。B) Oracle 数据库中,用SQL” delete tableName where 条件” 删除记录时,若该记录有外键引用,则不能删除该记录。C) 主键和外键字段值都不能为空。D) 主键和外键都能够提升数据操作效率。21、关于Oracle数据库索引的描述,不正确的是(多选):_A) 索引能提高对数据的查询、增加、修改、删除的效率。B)定期分析索引能有效提高查询效率。C)索引只能够对数据库字段建立。D)尽量做到数据表每个字段都建立索

有以下程序 include int fun(int a, int b) { if(b==0) return a;

有以下程序 #include <stdio.h> int fun(int a, int b) { if(b==0) return a; else return(fun(-a,-b)); } main() { printf("%d\n",fun(4,2)); } 程序的运行结果是______。

A.1

B.2

C.3

D.4


正确答案:B
解析:在调用一个函数的过程中又出现直接或间接调用该函数本身,称为函数的递归调用。本题考查的是函数递归调用。首先当a=4,b=2时,调用fun(4,2),不满足条件b==0,继续调用fun函数;此时a=3,b=1,即调用fun(3,1),不满足条件b=0,继续调用fun函数;此时a=2,b=0,满足条件b=0,返回a的值2。


有如下类定义: class Test { public: Test(){a=0;c=0} //① int f(int a)const{this->a=a;} //② static int g(){return a;} //③ void h(int b){Test::b;}; //④ private: int a; static int b; const int C; }; int Test::b=0; 在标注号码的行中,能被正确编译的是( )。

A.①

B.②

C.③

D.④


正确答案:D
解析:此题考查的是类的定义。一个类的长数据成员的初始化只能在成员初始化列表中进行,故选项A) 错误;常成员函数不能更新对象的数据成员,故选项B) 错误;静态成员函数可以直接访问类中说明的静态成员,但不能直接访问类中说明的非静态成员,故选项C) 错误。


有以下程序:include using namespace std;class A{private: int x,y;public: void se

有以下程序: #include <iostream> using namespace std; class A { private: int x,y; public: void set (int i,int j) { x=i; y=j; } int get_y() { return y; } }; class box { private: int length,width; A label; public: void set(int 1,int w, int s,int p) { length=1; width=w; label.set(s,p); } int get_area() { return length*width; } }; int main() { box small; small.set(2,4,1,35); cout<<small.get_area()<<end1; return 0; } 运行后的输出结果是( )。

A.8

B.4

C.35

D.70


正确答案:A
解析:本题考核成员对象的应用。类box的成员函数set()为设置对象的坐标值和对象的长、宽值。成员函数setarea返回该对象的面积。程序最后输出为8。


有如下类定义: class Test { public: Test(){a=0;c=0;} //① int f(int a)const {this->a=a;} //② static int g(){return a;} //③ void h(int b){Test::b=b;}; //④ private: int a; static int b; const int c; }; int Test::b=0; 在标注号码的行中,能被正确编译的是

A.①

B.②

C.③

D.④


正确答案:D
解析:本题考查了类的定义。一个类的常数据成员的初始化只能在成员初始化列表中进行,所以选项A不正确。常成员函数不能更新对象的数据成员,所以选项B不正确。静态成员函数可以直接访问类中说明的静态成员,但不能直接访问类中说明的非静态成员,所以选项C也不正确。故应该选择D。


若有以下程序:include using namespace std;define PI 3.14class Point{private: in

若有以下程序: #include <iostream> using namespace std; #define PI 3.14 class Point { private: int x,y; public: Point(int a,int b) { x=a; y=b; } int getx() { return x; } int gety() { return y; } }; class Circle : public Point { private: int r; public: Circle(int a, int b,int c) :Point(a,b) { r=c; } int getr() { return r; } double area() { return PI*r*r; } }; int main() { Circle c1(5,7,10); cout<<c1.area()<<end1; return 0; } 程序执行后的输出结果是( )。

A.314

B.157

C.78.5

D.153.86


正确答案:A
解析:本题考核派生类的定义和应用。本程序设计了一个点类Point,包含了横、纵两个坐标数据x和y,由它派生出了圆类Circle,并加入了新的数据成员,即一个半径数据,和一个求圆面积的函数成员area。在主函数中,首先定义了一个圆Circle类的对象c1,并通过它的构造函数初始化其数据成员。由此可知,其半径r的值为10,所以其面积为PI*10*10=314,即对象c1的函数成员area的返回值为314。

更多 “全省北京上元思创科技有限公司招聘JAVA面试模拟题考试专题训练” 相关考题
考题 给定java代码如下所示,在A处新增下列()方法,是对cal方法的重载。public class Test {  public void cal(int x, int y, int z) { } //A } A、public int cal(int x,int y,float z){return 0;}B、public int cal(int x,int y,int z){return 0;}C、public void cal(int x,int z){}D、public viod cal(int z,int y,int x){}正确答案:A,C

考题 1. class Over{   2. int doIt(long x) { return 3;}   3. }   4.   5. class Under extends Over{   6. //insert code here 7. }   和四个方法:   short doIt(int y) {return 4;}   int doIt(long x,long y){return 4;}   private int doIt(Short y){ return 4;}   protected int doIt(long x){return 4;}   分别插入到第6行,有几个可以通过编译?()  A、2B、3C、4D、0E、1正确答案:C

考题 1. public class Blip {  2. protected int blipvert(int x) { return 0; }  3. }  4. class Vert extends Blip {  5. // insert code here  6. }  Which five methods, inserted independently at line 5, will compile?()  A、 public int blipvert(int x) { return 0; }B、 private int blipvert(int x) { return 0; }C、 private int blipvert(long x) { return 0; }D、 protected long blipvert(int x, int y) { return 0; }E、 protected int blipvert(long x) { return 0; }F、 protected long blipvert(long x) { return 0; }G、protected long blipvert(int x) { return 0; }正确答案:A,C,D,E,F

考题 class A {  protected int method1(int a, int b) { return 0; }  }  Which two are valid in a class that extends class A?() A、 public int method1(int a, int b) { return 0; }B、 private int method1(int a, int b) { return 0; }C、 private int method1(int a, long b) { return 0; }D、 public short method1(int a, int b) { return 0: }E、 static protected int method1(int a, int b) { return 0; }正确答案:A,C

考题 多选题class A {  protected int method1(int a, int b) { return 0; }  }  Which two are valid in a class that extends class A?()Apublic int method1(int a, int b) { return 0; }Bprivate int method1(int a, int b) { return 0; }Cprivate int method1(int a, long b) { return 0; }Dpublic short method1(int a, int b) { return 0: }Estatic protected int method1(int a, int b) { return 0; }正确答案:D,B解析:暂无解析

考题 多选题给定java代码如下所示,在A处新增下列()方法,是对cal方法的重载。public class Test {  public void cal(int x, int y, int z) { } //A }Apublic int cal(int x,int y,float z){return 0;}Bpublic int cal(int x,int y,int z){return 0;}Cpublic void cal(int x,int z){}Dpublic viod cal(int z,int y,int x){}正确答案:B,D解析:暂无解析

考题 多选题Given the following code, which method declarations, when inserted at the indicated position, will not cause the program to fail compilation?()   public class Qdd1f {   public long sum(long a, long b) {  return a + b;  }   // insert new method declaration here  }Apublic int sum(int a, int b) { return a + b; }Bpublic int sum(long a, long b) { return 0; }Cabstract int sum();Dprivate long sum(long a, long b) { return a + b; }Epublic long sum(long a, int b) { return a + b; }正确答案:B,C解析:暂无解析

考题 多选题Given: Which five methods, inserted independently at line 5, will compile?()Aprotected int blipvert(long x) { return 0; }Bprotected long blipvert(int x) { return 0; }Cprivate int blipvert(long x) { return 0; }Dprivate int blipvert(int x) { return 0; }Epublic int blipvert(int x) { return 0; }Fprotected long blipvert(long x) { return 0; }Gprotected long blipvert(int x, int y) { return 0; }正确答案:D,B解析:暂无解析

考题 public class Score implements Comparable {  private int wins, losses;  public Score(int w, int 1) { wins = w; losses = 1; }  public int getWins() { return wins; }  public int getLosses() { return losses; }  public String toString() {  return “<“ + wins + “,“ + losses + “>”; }  // insert code here  }  Which method will complete this class?() A、 public int compareTo(Object o) {/*mode code here*/}B、 public int compareTo(Score other) {/*more code here*/}C、 public int compare(Score s1,Score s2){/*more code here*/}D、 public int compare(Object o1,Object o2){/*more code here*/}正确答案:B

考题 Given the following code, which method declarations, when inserted at the indicated position, will not cause the program to fail compilation?()   public class Qdd1f {   public long sum(long a, long b) {  return a + b;  }   // insert new method declaration here  }  A、public int sum(int a, int b) { return a + b; }B、public int sum(long a, long b) { return 0; }C、abstract int sum();D、private long sum(long a, long b) { return a + b; }E、public long sum(long a, int b) { return a + b; }正确答案:A,E