当前位置:文档之家› java英文笔试题

java英文笔试题

java英文笔试题
java英文笔试题

1.Which of the following lines will compile without warning or error.

答案(5)

1) float f=1.3;

2) char c="a";

3) byte b=257;

4) boolean b=null;

5) int i=10;

2. What will happen if you try to compile and run the following code

public class MyClass {

public static void main(String arguments[]) {

amethod(arguments);

}

public void amethod(String[] arguments) {

System.out.println(arguments);

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

}

}

答案(1)

1) error Can't make static reference to void amethod.

2) error method main not correct

3) error array must include parameter

4) amethod must be declared with String

3. Which of the following will compile without error

答案(23)

1) import java.awt.*;

package Mypackage;

class Myclass {}

2) package MyPackage;

import java.awt.*;

class MyClass{}

3) /*This is a comment */

package MyPackage;

import java.awt.*;

class MyClass{}

4. What will be printed out if this code is run with the following command line? java myprog good morning

public class myprog{

public static void main(String argv[])

{

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

}

}

答案(4)

1) myprog

2) good

3) morning

4) Exception raised:

"https://www.doczj.com/doc/2a8200492.html,ng.ArrayIndexOutOfBoundsException: 2"

5. What will happen when you compile and run the following code? public class MyClass{

static int i;

public static void main(String argv[]){

System.out.println(i);

}

}

答案(4)

1) Error Variable i may not have been initialized

2) null

3) 1

4) 0

6. What will happen if you try to compile and run the following code? public class Q {

public static void main(String argv[]){

int anar[]=new int[]{1,2,3};

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

}

}

答案(3)

1) 1

2) Error anar is referenced before it is initialized

3) 2

4) Error: size of array must be defined

7. What will happen if you try to compile and run the following code? public class Q {

public static void main(String argv[]){

int anar[]=new int[5];

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

}

}

答案(3)

1) Error: anar is referenced before it is initialized

2) null

3) 0

4) 5

8. What will be the result of attempting to compile and run the following code?

答案(3)

abstract class MineBase {

abstract void amethod();

static int i;

}

public class Mine extends MineBase {

public static void main(String argv[]){

int[] ar=new int[5];

for(i=0;i < ar.length;i++)

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

}

}

1) a sequence of 5 0's will be printed

2) Error: ar is used before it is initialized

3) Error Mine must be declared abstract

4) IndexOutOfBoundes Error

9. What will be printed out if you attempt to compile and run the following code ? int i=1;

switch (i) {

case 0:

System.out.println("zero");

break;

case 1:

System.out.println("one");

case 2:

System.out.println("two");

default:

System.out.println("default");

}

答案(3)

1) one

2) one, default

3) one, two, default

4) default

10. Which of the following lines of code will compile without error

答案(23)

1) int i=0;

if(i) {

System.out.println("Hello");

}

2) boolean b=true;

boolean b2=true;

if(b==b2) {

System.out.println("So true");

}

3) int i=1;

int j=2;

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

System.out.println("OK");

4) int i=1;

int j=2;

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

System.out.println("OK");

11. What will be output if you try to compile and run the following code, but there is no file called Hello.txt in the current directory?.

import java.io.*;

public class Mine

{

public static void main(String argv[])

{

Mine m=new Mine();

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

}

public int amethod()

{

try

{

FileInputStream dis

=new FileInputStream("Hello.txt");

}

catch (FileNotFoundException fne)

{

System.out.println("No such file found");

return -1;

}

catch(IOException ioe)

{}

finally

{

System.out.println("Doing finally");

}

return 0;

}

}

答案(3)

1) No such file found

2 No such file found ,-1

3) No such file found, Doing finally, -1

4) 0

12.Which of the following statements are true?

答案(1)

1) Methods cannot be overriden to be more private

2) static methods cannot be overloaded

3) private methods cannot be overloaded

4) An overloaded method cannot throw exceptions not checked in the base class

13.What will happen if you attempt to compile and run the following code?

答案(3)

class Base {}

class Sub extends Base {}

class Sub2 extends Base {}

public class CEx{

public static void main(String argv[]){

Base b=new Base();

Sub s=(Sub) b;

}

}

1) Compile and run without error

2) Compile time Exception

3) Runtime Exception

14.Which of the following statements are true?

答案(123)

1) System.out.println( -1 >>> 2);will output a result larger than 10

2) System.out.println( -1 >>> 2); will output a positive number

3) System.out.println( 2 >> 1); will output the number 1

4) System.out.println( 1 <<< 2); will output the number 4

15.What will happen when you attempt to compile and run the following code? public class Tux extends Thread{

static String sName = "vandeleur";

public static void main(String argv[]){

Tux t = new Tux();

t.piggy(sName);

System.out.println(sName);

}

public void piggy(String sName){

sName = sName + " wiggy";

start();

}

public void run(){

for(int i=0;i < 4; i++){

sName = sName + " " + i;

}

}

}

答案(4)

1) Compile time error

2) Compilation and output of "vandeleur wiggy"

3) Compilation and output of "vandeleur wiggy 0 1 2 3"

4) Compilation and output of either "vandeleur", "vandeleur 0", "vandeleur 0 1" "vandaleur 0 1 2" or "vandaleur 0 1 2 3"

16.What will be displayed when you attempt to compile and run the following code

//Code start

import java.awt.*;

public class Butt extends Frame{

public static void main(String argv[]){

Butt MyBut=new Butt();

}

Butt(){

Button HelloBut=new Button("Hello");

Button ByeBut=new Button("Bye");

add(HelloBut);

add(ByeBut);

setSize(300,300);

setVisible(true);

}

}

//Code end

答案(3)

1) Two buttons side by side occupying all of the frame, Hello on the left and Bye on the right

2) One button occupying the entire frame saying Hello

3) One button occupying the entire frame saying Bye

4) Two buttons at the top of the frame one saying Hello the other saying Bye

17.What will be output by the following code?

public class MyFor{

public static void main(String argv[]){

int i;

int j;

outer:

for (i=1;i <3;i++)

inner:

for(j=1; j<3; j++) {

if (j==2)

continue outer;

System.out.println("Value for i=" + i + " Value for j=" +j); }

}

}

答案(12)

1) Value for i=1 Value for j=1

2) Value for i=2 Value for j=1

3) Value for i=2 Value for j=2

4) Value for i=3 Value for j=1

18.Which statement is true of the following code?

public class Agg{

public static void main(String argv[]){

Agg a = new Agg();

a.go();

}

public void go(){

DSRoss ds1 = new DSRoss("one");

ds1.start();

}

}

class DSRoss extends Thread{

private String sTname="";

DSRoss(String s){

sTname = s;

}

public void run(){

notwait();

System.out.println("finished");

}

public void notwait(){

while(true){

try{

System.out.println("waiting");

}catch(InterruptedException ie){}

System.out.println(sTname);

notifyAll();

}

}

}

答案(4)

1) It will cause a compile time error

2) Compilation and output of "waiting"

3) Compilation and output of "waiting" followed by "finished"

4) Runtime error, an exception will be thrown

19.Which of the following methods can be legally inserted in place of the comment //Method Here ?

class Base{

public void amethod(int i) { }

}

public class Scope extends Base{

public static void main(String argv[]){

}

//Method Here

}

答案(23)

1) void amethod(int i) throws Exception {}

2) void amethod(long i)throws Exception {}

3) void amethod(long i){}

4) public void amethod(int i) throws Exception {}

20.You have created a simple Frame and overridden the paint method as follows

public void paint(Graphics g){

g.drawString("Dolly",50,10);

}

What will be the result when you attempt to compile and run the program?

答案(3)

1) The string "Dolly" will be displayed at the centre of the frame

2) An error at compilation complaining at the signature of the paint method

3) The lower part of the word Dolly will be seen at the top of the frame, with the top hidden.

4) The string "Dolly" will be shown at the bottom of the frame.

21.What will be the result when you attempt to compile this program?

public class Rand{

public static void main(String argv[]){

iRand = Math.random();

System.out.println(iRand);

}

}

答案(1)

1) Compile time error referring to a cast problem

2) A random number between 1 and 10

3) A random number between 0 and 1

4) A compile time error about random being an unrecognised method

22.Given the following code

import java.io.*;

public class Th{

public static void main(String argv[]){

Th t = new Th();

t.amethod();

}

public void amethod(){

try{

ioCall();

}catch(IOException ioe){}

}

}

What code would be most likely for the body of the ioCall method

答案(1)

1) public void ioCall ()throws IOException{

DataInputStream din = new DataInputStream(System.in);

din.readChar();

}

2) public void ioCall ()throw IOException{

DataInputStream din = new DataInputStream(System.in);

din.readChar();

}

3) public void ioCall (){

DataInputStream din = new DataInputStream(System.in);

din.readChar();

}

4) public void ioCall throws IOException(){

DataInputStream din = new DataInputStream(System.in);

din.readChar();

}

23.What will happen when you compile and run the following code?

public class Scope{

private int i;

public static void main(String argv[]){

Scope s = new Scope();

s.amethod();

}//End of main

public static void amethod(){

System.out.println(i);

}//end of amethod

}//End of class

答案(3)

1) A value of 0 will be printed out

2) Nothing will be printed out

3) A compile time error

4) A compile time error complaining of the scope of the variable i

24.You want to lay out a set of buttons horizontally but with more space between the first button and the rest. You are going to use the GridBagLayout manager to control the way the buttons are set out. How will you modify the way the GridBagLayout acts in order to change the spacing around the first button?

答案(2)

1) Create an instance of the GridBagConstraints class, call the weightx() method and then pass the GridBagConstraints instance with the component to the setConstraints method of the GridBagLayout class.

2) Create an instance of the GridBagConstraints class, set the weightx field and then pass the GridBagConstraints instance with the component to the setConstraints method of the GridBagLayout class.

3) Create an instance of the GridBagLayout class, set the weightx field and then call the setConstraints method of the GridBagLayoutClass with the component as a parameter.

4) Create an instance of the GridBagLayout class, call the setWeightx() method and then pass the GridBagConstraints instance with the component to the setConstraints method of the GridBagLayout class.

25.Which of the following can you perform using the File class?

答案(23)

1) Change the current directory

2) Return the name of the parent directory

3) Delete a file

4) Find if a file contains text or binary information

26.Which statement is true of the following code?

public class Rpcraven{

public static void main(String argv[]){

Pmcraven pm1 = new Pmcraven("One");

pm1.run();

Pmcraven pm2 = new Pmcraven("Two");

pm2.run();

}

}

class Pmcraven extends Thread{

private String sTname="";

Pmcraven(String s){

sTname = s;

}

public void run(){

for(int i =0; i < 2 ; i++){

try{

sleep(1000);

}catch(InterruptedException e){}

yield();

System.out.println(sTname);

}

}

}

答案(2)

1) Compile time error, class Rpcraven does not import https://www.doczj.com/doc/2a8200492.html,ng.Thread

2) Output of One One Two Two

3) Output of One Two One Two

4) Compilation but no output at runtime

27.You are concerned that your program may attempt to use more memory than is available. To avoid this situation you want to ensure that the Java Virtual Machine will run its garbage collection just before you start a complex routine. What can you do to be certain that garbage collection will run when you want .

答案(1)

1) You cannot be certain when garbage collection will run

2) Use the Runtime.gc() method to force garbage collection

3) Ensure that all the variables you require to be garbage collected are set to null

4) Use the System.gc() method to force garbage collection

28、Which statements about the garbage collection are true?

答案(2)

1. The program developer must create a thread to be responsible for free the memory.

2. The garbage collection will check for and free memory no longer needed.

3. The garbage collection allow the program developer to explicity and immediately free the memory.

4. The garbage collection can free the memory used java object at expect time.

29.You have these files in the same directory. What will happen when you attempt to compile and run Class1.java if you have not already compiled Base.java

//Base.java

package Base;

class Base{

protected void amethod(){

System.out.println("amethod");

}//End of amethod

}//End of class base

package Class1;

//Class1.java

public class Class1 extends Base{

public static void main(String argv[]){

Base b = new Base();

b.amethod();

}//End of main

}//End of Class1

答案(4)

1) Compile Error: Methods in Base not found

2) Compile Error: Unable to access protected method in base class

3) Compilation followed by the output "amethod"

4)Compile error: Superclass Class1.Base of class Class1.Class1 not found

30.What will happen when you attempt to compile and run the following code

class Base{

private void amethod(int iBase){

System.out.println("Base.amethod");

}

}

class Over extends Base{

public static void main(String argv[]){

Over o = new Over();

int iBase=0;

o.amethod(iBase);

}

public void amethod(int iOver){

System.out.println("Over.amethod");

}

}

答案(4)

1) Compile time error complaining that Base.amethod is private

2) Runtime error complaining that Base.amethod is private

3) Output of "Base.amethod"

4) Output of "Over.amethod"

一个袋子中有100个黑球,100个白球,每次从中取出两个球,然后放回一个球,如果取出两个球颜色相同,则放入一个黑球,如果取出一百一黑,则放入一个白球,请问到最后袋中剩下的球的颜色:

1)黑球2)白球3)不一定。黑球

给出证明。

建立一个数据库模型,用于管理一个公司部门及其内部雇员,每个部门都有一个负责人。根据你的数据库模型,编写sql语句建立你的数据库表,给出一个雇员的姓名,查询该雇员所属的部门负责人。

1. 5)

2. 1)

3. 2)3)

4. 4)

5. 4)

6. 3)

7. 3)

8. 3)

9. 3)

10. 2)3)

11. 3)

12. 1)

13. 3)

14. 1)2)3)

15. 4)

16. 3)

17. 1)2)

18. 4)

19. 2)3)

20. 3)

21. 1)

22. 1)

23. 3)

24. 2)

25. 2,3

26. 2)

27. 1)

28. 2

29. 4

30. 4

黑球。

Java试题(二)(时间40分钟)

一、选择:

1.欲构造ArrayList类的一个实例,此类继承了List接口,下列哪个方法是正确的?

A.ArrayList myList=new object();

B.List myList=new ArrayList();

C.ArrayList myList=new List();

D.List myList=new List();

2.指出正确的表达式。

A.byte b=128;

B.Boolean b=null;

C.long=0xfffL

D.double=0.9239d

3.指出下列程序运行的结果。

public class Example{

String str=new String (“good”);

char[]ch={…a?,?b?,?c?};

public static void main(String args[]) {

Example ex=new example();

ex.change(ex.str,ex.ch);

System.out.print(ex.str=”and ”);

System.out.print(ex.ch);

}

public void change(String str,char ch[]) {

str=”test ok”;

ch[0]=?g?;

}

}

A.good and abc

B.good and gbc

C.test ok and abc

D.test ok ang gbc

4.运行下列程序,会产生什么结果?

public class X extends Thread implements Rumble{

public void run() {

System.out.println(“this is run()”);

}

public static void main(String args[])

{

Thread t=new Thread (new X());

t.start();

}

}

A.第一行会产生编译错误

B.第六行会产生编译错误

C.第六行会产运行错误

D.程序会运行和启动

5.哪个关键字可以对对象加互斥锁?

A.transient

B.synchronized

C.serialize

D.static

6.下列代码哪一行会出错?

1) public void modify() {

2) int I,j,k;

4) while (I>0) {

5) j=I*2;

6) System.out.println(“The value of j is ”+j);

7) k=k+1;

8) I--;

9) }

10) }

A.line 4

B.line 6

C.line 7

D.line 8

二、多面选择

1.public class parent {

int change() {}

}

class Child extends Parent{}

哪些方法可以加入类Child中?

A.public int change() {}

B.int chang (int i) {}

C.private int change () {}

D.abstract int chang () {} 2.String s = “hello”;

String t = “hello”;

char c[] ={…h?,?e?,?l?,?l?,?o?};

下列哪些表达式返回true?

A.s.equals(t);

B.t.equals(c);

C.s==t;

D.t.equals(new String (“hello”));

3.给出下面代码段:

1.switch(m)

2.{ case 0: System.out.println(“case 0”);

3.case1: System.out.println(“case 1”); break; 4.case2:

5.default:System.out.println(“default”);

6.}

下面m的哪些值将引起”default”的输出?

A.0

B.1

C.2

D.3

4.对于下列代码:

public class Sample {

long length;

public Sample (long 1) {length = 1;}

public static void main(String arg[]) {

Sample s1,s2,s3;

s1 = new Sample(21L);

s2 = new Sample(21L);

s3 = s2;

long m = 21L;

}

下列哪些表达式返回值为…true??

A.s1==s2;

B. s2==s3;

C.m==s1;

D.s1.equals(m)

5.给定下面的代码片段:

public void Test() {

try {

method();

System.out.println(“Hello World”);

}

catch (ArrayIndexOutOfBoundsException e)

{

System.out.println(“Exception1”);

}

finally {

System.out.println(“Thank you!”);

}

}

如果函数method正常运行并返回,会显示下面的哪些信息?

A. Hello World

B.Exception

C.Exception1

D.Thank you!

6.关于session的论述正确的有:

A.一个session可以对应数个用户

B.一个session只能对应一个用户

C.可以手动关闭一个session

D.session如果不手动关闭,会一直存在Server中

三、填空题:

1.请描述一下Test.java编译后,在控制台执行命令“java Test”后的输出结果:____________________________

Test.java内容如下:

class A

{

public A()

{

System.out.print(“A”);

}

}

class B extends A

{

public B()

{

System.out.print(“B”);

Aa=new A();

}

}

public class Test

{

public Test()

{

System.out.print(“Test”);

}

public static void main(String[] a)

{

Bb=new B();

}

}

2.下列代码不能编译的原因是:_____________________________________

Class A {

Private int x;

Public static void main(String args[])

{

new B();

}

class B{

B() {System.out.println(x);}

}

}

4.下面程序建立一个服务器通过监听8080端口向客户端输出”Welcome!”字符串,请补充缺少的程序片断:

public class WelcomeServer

{

public static void main(String[] a) throws I0exception

{

____1_____;

System.out.println(“WelcomeServer started!”);

while(true)

{

Socket client = ____2____;

System.out.println(“A client come!”);

try

{

PrintWriter writer = new PrintWriter(

new BufferedWriter(____3____(____4____)));

writer.println(“Welcome!”);

}

catch (I0Exception ioe2)

{

System.out.println(“Something error!”);

}

}

}

}

Java面试题带答案

J a v a面试题带答案 Document number:BGCG-0857-BTDO-0089-2022

湖南世杰Java工程师面试题 选择题: 单选题 1,以下java程序代码,执行后的结果是( ) map= ("name",null); ("name","Jack"); 0 B: null C: 1 D: 2 答案:C 2,执行以下程序后的输出结果是( ) Public class Test { Public static void main(String[] args) { StringBuffer a = new StringBuffer("A"); StringBuffer b = new StringBuffer("B"); operator(a, b);

+","+ b); } Public static void operator(StringBuffer x, StringBuffer y) { (y); y = x; } } A: A,A B: A,B C: B,B D: AB,B 答案:D 3,关于依赖注入,下列选项中说法错误的是( ) A:依赖注入能够独立开发各组件,然后根据组件间关系进行组装 B:依赖注入使组件之间相互依赖,相互制约 C:依赖注入提供使用接口编程 D:依赖注入指对象在使用时动态注入 答案:B

4,关于spring说法错误的是( ) A: spring是一个轻量级JAVA EE的框架集合 B: spring是“依赖注入”模式的实现 C: 使用spring可以实现声明事务 D: spring提供了AOP方式的日志系统 答案:D 5,要在session对象中保存属性,可以使用以下哪个语句( ) A: (“key”,”value”) B: (“key”,”value”) C: (“key”) D: (“key”) 答案:B 6,关于以下程序代码的说明正确的是( ) Public class HasStatic{ Private static int x = 100; Public static void main(String args[]){

Java面试题大全(答案版)

1、一个".java"源文件中是否可以包括多个类(不是内部类)?有什么限制? 可以,但是只能有一个类用public修饰,并且用public修饰的类名与文件名要一致 2、&和&&的区别。 &和&&都可以用作逻辑与; &&还具有短路功能,即如果第一个表达式的结果为false,则不再计算第二个表达式; &还可以用作位运算符,当&操作符两边的表达式不是boolean类型时,&表示按位与操作。 3、Java有没有goto? java中的保留字,现在没有在java中使用。 4、在JAVA中,如何跳出当前的多重嵌套循环? break+变量控制与return 5、switch是否能作用在byte(拜特)上,是否能作用在long上,是否能作用在String上? Switch可以作用在int上,而byte可以隐式转换为int 所以能作用在byte上 不能作用在long上,也不能作用在String上 6、short s1 = 1; s1 = s1 + 1;有什么错? short s1 = 1; s1 += 1;有什么错? 1在java中为int数据类型,short+int=int,大类型转为小类型,编译时,会报告需要强制转换类型的错误。s1+=1不会报,因为JVM会对它特殊处理(自动强转) 7、char型变量中能不能存贮一个中文汉字?为什么? 可以,char型变量是用来存储unicode(依妮Q特)编码的,而unicode编码包含了中文,所以是可以保存的 8、编程题: 用最有效率的方法算出2乘以8等於几? 2<<3,表示将2左移3位;一个数左移几位就表示这个数乘以了2的几次方,左移运算,CPU直接支持,所以是最有效率的 9、请设计一个一百亿的计算器 思路:用两个数组分别保存两个操作数,再新建一个数组保存结果。 10、使用final关键字修饰一个变量时,是引用不能变,还是引用的对象不能变? 引用变量不能变 11、"=="和equals方法究竟有什么区别? ==和equals方法都可以用来比较两个对象是否是同一个对象。 ==还可以比较两个变量的值是否相等。 equals是Object类中的方法,可以由子类重写此方法,实现内容相等。 12、静态变量和实例变量的区别? 语法上不同: 静态变量前要加static关键字,实例变量不需要 程序运行时不同: 实例变量是属于某个对象的,只有创建了对象,才会为这个对象的实例变量分配空间。静态变量是属于类的,当程序加载了这个类的字节码文件,就会为静态变量分配空间,并且所有对象共享这个变量 13、是否可以从一个static方法内部发出对非static方法的调用? 不可以,非static方法需要与对象关联在一起的,而static方法调用时不需要对象,可以直接调用,也就是说调用static方法时,可能还没有创建任何实例 14、Integer与int的区别 int是java中的8种基本数据类型之一,默认值是0,Integer是int的包装类,默认值是null,即Integer可以表示未赋值和赋值为0 15、(麦死)Math.round(乱的)(11.5)等於多少? Math.round(-11.5)等於多少?

Java经典面试题大全_带答案

Java经典面试题带答案一、单项选择题 1.Java是从()语言改进重新设计。 A.Ada B.C++ C.Pasacal D.BASIC 答案:B 2.下列语句哪一个正确() A.Java程序经编译后会产生machine code B.Java程序经编译后会产生byte code(字节码) C.Java程序经编译后会产生DLL D.以上都不正确 答案:B 3.下列说法正确的有() A.class中的constructor不可省略 B.constructor必须与class同名,但方法不能与class同名C.constructor在一个对象被new时执行(构造器) D.一个class只能定义一个constructor 答案:C 4.提供Java存取数据库能力的包是() A.Java.sql /sql/数据库还有Oracle 也是一种数据库 B.java.awt C.https://www.doczj.com/doc/2a8200492.html,ng D.java.swing 答案:A 5.下列运算符合法的是() A.&& B.<> C.if D.:= 答案:A 6.执行如下程序代码 a=0;c=0; do{ --c; a=a-1; }while(a>0); 后,C的值是() A.0 B.1 C.-1 D.死循环

答案:C 7.下列哪一种叙述是正确的() A.abstract修饰符可修饰字段、方法和类 B.抽象方法的body部分必须用一对大括号{}包住 C.声明抽象方法,大括号可有可无 D.声明抽象方法不可写出大括号 答案:D 8.下列语句正确的是() A.形式参数可被视为localvariable B.形式参数可被字段修饰符修饰 C.形式参数为方法被调用时,真正被传递的参数 D.形式参数不可以是对象 答案:A 9.下列哪种说法是正确的() A.实例方法可直接调用超类的实例方法 B.实例方法可直接调用超类的类方法 C.实例方法可直接调用其他类的实例方法 D.实例方法可直接调用本类的类方法 答案:D 二、多项选择题 1.Java程序的种类有() A.类(Class) B.Applet C.Application D.Servlet 2.下列说法正确的有() A.环境变量可在编译sourcecode时指定 B.在编译程序时,所能指定的环境变量不包括class path C.javac一次可同时编译数个Java源文件 D.javac.exe能指定编译结果要置于哪个目录(directory)答案:BCD 3.下列标识符不合法的有() A.new B.$Usdollars C.1234 D.car.taxi 答案:ACD 4.下列说法错误的有() A.数组是一种对象 B.数组属于一种原生类 C.intnumber=[]={31,23,33,43,35,63} D.数组的大小可以任意改变 答案:BCD 5.不能用来修饰interface的有()

Java开发工程师笔试题(带答案)

Java开发工程师笔试试题 (请不要在试题上留任痕迹,所有答案均写在答题纸上) 一.编程题(共26分) 1.任意写出一种排序算法。(6分) public void sort(int [] array){ //代码区 } 2.求1+2+3+..n(不能使用乘除法、for 、while 、if 、else 、switch 、case 等关键字 以及条件判断语句)(8分) public int sum(int n){ //代码区 return 0; } 3.完成下面法,输入一个整数,输出如下指定样式图案。(12分) 输入:3, 输出: 1*2*3 7*8*9 4*5*6

输入:4 输出: 1*2*3*4 9*10*11*12 13*14*15*16 5*6*7*8 public void drawNumPic(int n){ //代码区 } 二.选择题(定项选择每题3分,不定项选择每题4分,共63分) 1.在基本JAVA类型中,如果不明确指定,整数型的默认是__类型,带小数的默认是__类型?( B ) A.int float B.int double C.long float D.long double 2.只有实现了__接口的类,其对象才能序列化( A ) A.Serializable B.Cloneable https://www.doczj.com/doc/2a8200492.html,parable

D.Writeable 3.代码System. out. println(10 % 3 * 2);将打印出?( B ) A. 1 B.2 C.4 D.6 4.以下程序运行的结果为( A ) public class Example extends Thread{ @Override public void run(){ try{ Thread.sleep(1000); }catch (InterruptedException e){ e.printStackTrace(); } System.out.print("run"); } public static void main(String[] args){ Example example=new Example(); example.run(); System.out.print("main"); } } A.run main B.main run C.main D.run E.不能确定 5.下面有关java实例变量,局部变量,类变量和final变量的说法,错误的是?( B ) A.实例变量指的是类中定义的变量,即类成员变量,如果没有初始化,会有默认值

最新最新java笔试题及答案

一.选择题(1-10题每题2分,11-15题每题4分) 1.下面关于Java语言说法错误的是:() A.java语言是完全面向对象的 B。java语言支持多继承 C.java语言支持多线程 D。java语言最早是为消费电子产品领域设计的 2.下面标识符中正确的是:() A.*123 B。12java C.continue D。java$next 3.下列关于注释语句的描述中,正确的一项是() A。以//开始的是多行注释语句 B。以/*开始,*/结束的是单行注释语句 C。以/**开始,*/结束的是可以用于生成帮助文档的注释语句 D。以/**开始,*/结束的是单行注释语句 4.为了区分重载多态中同名的不同方法,要求()。 A)形式参数个数或者类型不同 B)返回值类型不同 C)调用时用类名或对象名做前缀 D)形式参数名称不同 5.下面定义数组的格式中正确的是:() A.int a[10] B。int a=new int[10] C.int []a=new int[5] D.int a[] 6.下面说法中不正确的是:() A.类是对象的抽象,对象是类的实例 B。类是组成java程序的最小的单位 C.java语言支持多继承 D。java一个程序中只能有一个public类 7.定义类时,不可能用到的保留字是()。 A) private B) class C) extends D) implements 8.为 AB 类的定义一个公共的构造函数,该方法头的形式为()

A.void AB( ) B。public void method( ) C.public method ( ) D。public AB( ) 9.下面说法中不正确的是:() A.java中一个类只允许实现一个接口 B。抽象类中允许有非抽象方法的存在 C.类变量(实例变量)可以直接用类名调用 D。通过super可以调用基类的构造函数 10.容器JFrame 默认使用的布局编辑策略是() A.BorderLayout B。FlowLayout C。GridLayout D。CardLayout 11.以下哪个表达式是不合法的() A.String x=”Hello”; int y=9; x+=y; B.String x=”Hello”; int y=9; if(x= =y) { } C.String x=”Hello”; int y=9; x=x+y; D.String x=null; int y=(x!=null)&&(x.length()>0) 12.class person { public int addvalue(int a,int b) { int s; s=a+b; return s; } }

Java面试题(带答案)

湖南世杰Java工程师面试题选择题: 单选题 1,以下java程序代码,执行后的结果是( ) java.util.HashMap map=newjava.util.HashMap(); map.put("name",null); map.put("name","Jack"); System.out.println(map.size()); A: 0 B: null C: 1 D: 2 答案:C 2,执行以下程序后的输出结果是( ) Public class Test { Public static void main(String[] args) { StringBuffer a = new StringBuffer("A"); StringBuffer b = new StringBuffer("B"); operator(a, b); System.out.println(a +","+ b); } Public static void operator(StringBuffer x, StringBuffer y) { x.append(y); y = x; }

} A: A,A B: A,B C: B,B D: AB,B 答案:D 3,关于依赖注入,下列选项中说法错误的是( ) A:依赖注入能够独立开发各组件,然后根据组件间关系进行组装 B:依赖注入使组件之间相互依赖,相互制约 C:依赖注入提供使用接口编程 D:依赖注入指对象在使用时动态注入 答案:B 4,关于spring说法错误的是( ) A: spring是一个轻量级JAVA EE的框架集合 B: spring是“依赖注入”模式的实现 C: 使用spring可以实现声明事务 D: spring提供了AOP方式的日志系统 答案:D 5,要在session对象中保存属性,可以使用以下哪个语句( ) A: session.getAttribute(“key”,”value”) B: session.setAttribute(“key”,”value”) C: session.setAttribute(“key”) D: session.getAttribute(“key”) 答案:B 6,关于以下程序代码的说明正确的是?( ) Public class HasStatic{ Private static int x = 100;

java笔试题大集合及答案Java基础方面

Java基础方面: 1、作用域public,private,protected,以及不写时的区别 答:区别如下: 作用域当前类同一package 子孙类其他package public √√√√ protected √√√× friendly √√×× private √××× 不写时默认为friendly 2、Anonymous Inner Class (匿名内部类) 是否可以extends(继承)其它类,是否可以implements(实现)interface(接口) 答:匿名的内部类是没有名字的内部类。不能extends(继承) 其它类,但一个内部类可以作为一个接口,由另一个内部类实现 3、Static Nested Class 和Inner Class的不同 答:Nested Class (一般是C++的说法),Inner Class (一般是JAVA的说法)。Java内部类与C++嵌套类最大的不同就在于是否有指向外部的引用上。注:静态内部类(Inner Class)意味着1创建一个static内部类的对象,不需要一个外部类对象,2不能从一个static内部类的一个对象访问一个外部类对象 4、&和&&的区别 答:&是位运算符,表示按位与运算,&&是逻辑运算符,表示逻辑与(and) 5、Collection 和 Collections的区别 答:Collection是集合类的上级接口,继承与他的接口主要有Set 和List. Collections是针对集合类的一个帮助类,他提供一系列静态方法实现对各种集合的搜索、排序、线程安全化等操作 6、什么时候用assert 答:assertion(断言)在软件开发中是一种常用的调试方式,很多开发语言中都支持这种机制。在实现中,assertion就是在程序中的一条语句,它对一个boolean表达式进行检查,一个正确程序必须保证这个boolean表达式的值为true;如果该值为false,说明程序已经处于不正确的状态下,系统将给出警告或退出。一般来说,assertion用于保证程序最基本、关键的正确

Java面试经典试题和答案

Java面试经典试题和答案 Java面试经典试题和答案 常见的Java问题 1.什么是Java虚拟机?为什么Java被称作是“平台无关的编程语言”? Java虚拟机是一个可以执行Java字节码的虚拟机进程。Java源文件被编译成能被Java虚拟机执行的字节码文件。 Java被设计成允许应用程序可以运行在任意的平台,而不需要程序员为每一个平台单独重写或者是重新编译。Java虚拟机让这个变为可能,因为它知道底层硬件平台的指令长度和其他特性。 2.JDK和JRE的区别是什么? Java运行时环境(JRE)是将要执行Java程序的Java虚拟机。它同时也包含了执行applet需要的浏览器插件。Java开发工具包(JDK)是完整的Java软件开发包,包含了JRE,编译器和其他的工具(比如:JavaDoc,Java调试器),可以让开发者开发、编译、执行Java应用程序。 3.”static”关键字是什么意思?Java中是否可以覆盖(override)一个private或者是static的方法? “static”关键字表明一个成员变量或者是成员方法可以在没有所属的类的实例变量的情况下被访问。 Java中static方法不能被覆盖,因为方法覆盖是基于运行时动态绑定的,而static方法是编译时静态绑定的。static方法跟类的任何实例都不相关,所以概念上不适用。 4.是否可以在static环境中访问非static变量?

static变量在Java中是属于类的,它在所有的实例中的值是一 样的。当类被Java虚拟机载入的时候,会对static变量进行初始化。如果你的代码尝试不用实例来访问非static的变量,编译器会 报错,因为这些变量还没有被创建出来,还没有跟任何实例关联上。 5.Java支持的数据类型有哪些?什么是自动拆装箱? Java语言支持的8中基本数据类型是: byte short int long float double boolean char 自动装箱是Java编译器在基本数据类型和对应的对象包装类型 之间做的一个转化。比如:把int转化成Integer,double转化成double,等等。反之就是自动拆箱。 6.Java中的方法覆盖(Overriding)和方法重载(Overloading)是 什么意思? Java中的方法重载发生在同一个类里面两个或者是多个方法的 方法名相同但是参数不同的情况。与此相对,方法覆盖是说子类重 新定义了父类的方法。方法覆盖必须有相同的方法名,参数列表和 返回类型。覆盖者可能不会限制它所覆盖的方法的访问。 7.Java中,什么是构造函数?什么是构造函数重载?什么是复制 构造函数?

JAVA面试题(_华为)(答案)

软件开发应试人员考试试题(Java) 姓名:___________ 电话:___________ 以下信息有工作经验人员如实填写,应届毕业不填(时间从毕业参加工作算起) 从事Java开发时间____月熟悉JavaScrip时间____月 熟悉EXT开发时间____月熟悉PDM开发时间____月 熟悉的数据库及时间(如SQLServer 3个月,可多填)___________________ 一、JAVA基础 1、简述你所知道的JA V A修饰符及各自的使用机制?(public、abstract、final、synchronized、super…) public :允许所有客户访问 protected:只能在本包内被该类的子类所使用 private:只允许在本类内使用 abstract:没有提供实现,需要子类提供 static:与整个类相关,与单个对象无关 final:你只能定义一个实体一次,以后不能改变它或继承它。一个final修饰的类不能被子类化,一个final 修饰的方法不能被重写,一个final修饰的变量不能改变其初始值 synchronized:方法获得对对象监控的访问权;如果该方法是static类型的,获得是对类本身的访问权。super:构造器和方法,都用关键字super指向超类,但是用的方法不一样。方法用这个关键字去执行被重载的超类中的方法。 2. String、StringBuffer与StringBuilder之间区别?别简述各自的执行效率? 区别:String 类型和StringBuffer 类型的主要性能区别其实在于String 是不可变的对象, 因此在每次对String 类型进行改变的时候其实都等同于生成了一个新的String 对象,然后将指针指向新的String 对象,所以经常改变内容的字符串最好不要用String ,因为每次生成对象都会对系统性能产生影响,特别当内存中无引用对象多了以后,JVM 的GC 就会开始工作,那速度是一定会相当慢的, 执行速度:三者在执行速度方面的比较:StringBuilder > StringBuffer > String 使用场景:1.如果要操作少量的数据用= String 2.单线程操作字符串缓冲区下操作大量数据= StringBuilder 3.多线程操作字符串缓冲区下操作大量数据= StringBuffer 2、静态变量和实例变量的区别?能在静态方法中调用非静态变量吗? 静态变量属于类,该类不生产对象,通过类名就可以调用静态变量。实例变量属于该类的对象,必须产生该类对象,才能调用实例变量 静态方法及变量属于整个类,数据将会被存储在公共区域,非静态方法及变量属于对象 静态方法中无法调用实例变量,而实例方法却可以调用静态变量

Java经典面试笔试题及答案

1.什么是对象序列化,为什么要使用? 所谓对象序列化就是把一个对象以二进制流的方式保存到硬盘上。好处:方便远程调用。 2.值传递与引用传递的区别? 所谓值传递就是把一个对象的值传给一个新的变量,但是系统会给这个新的变量开辟一个新的内存空间。不会改变原有的值所谓引用传递就是把一个对象在堆中保存的数据传递给一个变量,此时新的变量与原有的变量对应同一个内存存储空间,当新的变量修改对象的属性时,内存中的数据也会修改。 3.接口与抽象类的区别? 1:接口里面不可以实现方法体,抽象类可以实现方法体。 2:接口可以多继承接口,抽象类不可以。 3:接口需要被子类实现,抽象类是要被子类继承(单一继承)。 4:接口中只能有公有的方法和属性而且必须赋初始值,抽象类中可以有私有方法和属性. 5: 接口中不能存在静态方法,但属性可以和final,抽象类中方法中可以有静态方法,属性也可以。 4.谈谈继承,为什么要使用继承? 所谓继承就是找出几个类中共同的部分,提取出来作为父类。而子类只需要继承父类,就可以共享父类的方法。 使用继承能够减少重复的代码。 5.方法重载的好处?

所谓重载就是在一个类中可以定义多个相同的方法,但是方法的参数类型和参数的个数以及顺序要不同。 重载的好处就是能够让我们很快的掌握该方法的功能,我们只要要记住该方法就能很快的理解该方法的参数以及参数的作用 6.项目中印象最深的部分? 我觉得在该项目中我体现到了反射技术的强大之处,原来我一直不清楚反射是一种什么样的技术,只知道一些概念上的知识,经过这个项目之后,终于知道该怎样灵活运用反射,以及在什么时候运用。 谈谈你对面向对象的理解与认识? 我觉得使用面向对象这种思维的方式比较符合我们人类的思想,不需要去学习一些什么新的思考方式,就按照现实生活做的一些故事就能让人理解该内容的知识以及他们的作用。 我的看法就是: 1:当加入新的功能的时候不会修改原有的代码。(面向接口编程) 2: 当我们写的一个类可以重复的运用在其他项目中。(代码的复用性) 3:当写一个新类的时候要考虑到他的可扩展性。(灵活性) 7.谈谈集合框架? 集合框架分为三部分,第一部分是collection接口,第二部分是Map接口、第三部分是collections帮助类 首先说一下collection接口,collection接口下面的接口分为set 接口、list接口,在往下面就是他们一些实现类。

华为java笔试题以及答案

最新华为java笔试题以及答案 华为作为世界500强企业之一,每年都会在各省市招募大量人才,因为其巨大的威望和声誉以及较好的薪酬,近年来华为成为很多学子争相进入的理想之地。尤其对于很多学计算机技术的人来说,更是一大吸引之地。然而,这么大的公司可不是想进就能进的。多年来,华为对人才的要求都很高,类别也多,已形成了完整的人才招聘体系。想进去,就需要各渠道想办法,首先要过笔试。本小编在此整理了华为java笔试题,以供大家参考: 一、单项选择题 1.下列运算符合法的是() A.&&B.<>C.ifD.:= 答案:A 2.下列语句哪一个正确() A.Java程序经编译后会产生machinecode B.Java程序经编译后会产生bytecode C.Java程序经编译后会产生DLL D.以上都不正确

答案:B 3.下列说法正确的有() A.class中的constructor不可省略 B.constructor必须与class同名,但方法不能与class同名C.constructor在一个对象被new时执行 D.一个class只能定义一个constructor 答案:C 4.提供Java存取数据库能力的包是() A.java.sqlB.java.awtC.https://www.doczj.com/doc/2a8200492.html,ngD.java.swing 答案:A 5.Java是从()语言改进重新设计。 A.AdaB.C++C.PasacalD.BASIC 答案:B 6.执行如下程序代码 a=0;c=0; do{

--c; a=a-1; }while(a>0); 后,C的值是() A.0B.1C.-1D.死循环 答案:C 7.下列哪一种叙述是正确的() A.abstract修饰符可修饰字段、方法和类 B.抽象方法的body部分必须用一对大括号{}包住C.声明抽象方法,大括号可有可无 D.声明抽象方法不可写出大括号 答案:D 8.下列语句正确的是() A.形式参数可被视为localvariable B.形式参数可被字段修饰符修饰 C.形式参数为方法被调用时,真正被传递的参数

2021年Java面试题带答案

湖南世杰Java工程师面试题选取题: 单选题 1,如下java程序代码,执行后成果是( ) java.util.HashMap map=newjava.util.HashMap(); map.put("name",null); map.put("name","Jack"); System.out.println(map.size()); A:0 B:null C:1 D:2 答案:C 2,执行如下程序后输出成果是( ) Public class Test { Public static void main(String[] args) { StringBuffer a = new StringBuffer("A"); StringBuffer b = new StringBuffer("B"); operator(a,b);

System.out.println(a +","+ b); } Public static void operator(StringBuffer x,StringBuffer y) { x.append(y);y = x; } } A:A,A B:A,B C:B,B D:AB,B 答案:D 3,关于依赖注入,下列选项中说法错误是( ) A:依赖注入可以独立开发各组件,然后依照组件间关系进行组装 B:依赖注入使组件之间互相依赖,互相制约 C:依赖注入提供使用接口编程 D:依赖注入指对象在使用时动态注入 答案:B 4,关于spring说法错误是( ) A:spring是一种轻量级JAVA EE框架集合 B:spring是“依赖注入”模式实现

java web开发人员面试题及答案

java 面试题 一.选择题(每题1分) 1. jsp 有几个内置对象?()(单选) A 5个 B 6个 C 9个 D 8个 2. 在JAVA中,如何跳出当前的多重嵌套循环?()(多选) A break B return C forward D finally 3. 四种会话跟踪技术,哪个范围最大?()(单选) A page B request C session D application 4. java中有几种方法可以实现一个线程?()(单选) A 1种 B 2种 C 3种 D 4种 5. 同步有几种实现方法()(单选) A 4种 B 2种 C 3种 D 1种 6. xml有哪些解析技术? ()(多选) A DOM B SAX C STAX D JDOM 7. 下列说法正确的是()(多选) A 构造器Constructor可被继承 B String类不可以继承 C 判断两个对象值相同用“==” D char型变量中能不能存贮一个中文汉字 8.下面说法错误的是()(单选) A Vector是线程安全的 B float f=3.4是正确的 C StringBuffer的长度是可变的 D StringBuffer的长度是不可变的 9. 下列关于集合的说法正确的是()(多选) A List 的具体实现包括 ArrayList 和 Vector B Map 集合类用于存储元素对(称作"键"和"值"),其中每个键映射到一个值 C Set的元素是有序的 D Hashtable 是线程安全的。 10. 下列关于线程说法正确的是()(多选) A 调用sleep不会释放对象锁。 B 调用wait方法导致本线程放弃对象锁 C 当一个线程进入一个对象的一个synchronized方法后,其它线程不可进入此对象的其它方法 D notify():唤醒全部处于等待状态的线程。 11. 给定JSP程序源码如下,该JSP运行后输出的结果是()。(单选) <%int Count=1;%> Count:<%=++Count%> A Count:1 B Count:2 C1:2 D Count: 12在J2EE中的一个JSP文件中,有表达式<%=2+3%>,它将输出()(单选) a)2+3 b)5 c)23 d)不会输出,因为表达式是错误的

java面试题及答案整理

java面试题及答案整理 1、面向对象的特征有哪些方面? 答:面向对象的特征主要有以下几个方面: - 抽象:抽象是将一类对象的共同特征总结出来构造类的过程,包括数据抽象和行为抽象两方面。抽象只关注对象有哪些属性和行为,并不关注这些行为的细节是什么。 - 继承:继承是从已有类得到继承信息创建新类的过程。提供继承信息的类被称为父类(超类、基类);得到继承信息的类被称为子类(派生类)。继承让变化中的软件系统有了一定的延续性,同时继承也是封装程序中可变因素的重要手段(如果不能理解请阅读阎宏博士的《Java与模式》或《设计模式精解》中关于桥梁模式的部分)。 - 封装:通常认为封装是把数据和操作数据的方法绑定起来,对数据的访问只能通过已定义的接口。面向对象的本质就是将现实世界描绘成一系列完全自治、封闭的对象。我们在类中编写的方法就是对实现细节的一种封装;我们编写一个类就是对数据和数据操作的封装。可以说,封装就是隐藏一切可隐藏的东西,只向外界提供最简单的编程接口(可以想想普通洗衣机和全自动洗衣机的差别,明显全自动洗衣机封装更好因此操作起来更简单;我们现在使用的智能手机也是封装得足够好的,因为几个按键就搞定了所有的事情)。 - 多态性:多态性是指允许不同子类型的对象对同一消息作出不同的响应。简单的说就是用同样的对象引用调用同样的方法但是做了不同的事情。多态性分为编译时的多态性和运行时的多态性。如果将对象的方法视为对象向外界提供的服务,那么运行时的多态性可以解释为:当A系统访问B系统提供的服务时,B

系统有多种提供服务的方式,但一切对A系统来说都是透明的(就像电动剃须刀是A系统,它的供电系统是B系统,B系统可以使用电池供电或者用交流电,甚至还有可能是太阳能,A系统只会通过B类对象调用供电的方法,但并不知道供电系统的底层实现是什么,究竟通过何种方式获得了动力)。方法重载(overload)实现的是编译时的多态性(也称为前绑定),而方法重写(override)实现的是运行时的多态性(也称为后绑定)。运行时的多态是面向对象最精髓的东西,要实现多态需要做两件事:1). 方法重写(子类继承父类并重写父类中已有的或抽象的方法);2). 对象造型(用父类型引用引用子类型对象,这样同样的引用调用同样的方法就会根据子类对象的不同而表现出不同的行为)。 2、String 是最基本的数据类型吗? 答:不是。Java中的基本数据类型只有8个:byte、short、int、long、float、double、char、boolean;除了基本类型(primitive type),剩下的都是引用类型(reference type),Java 5以后引入的枚举类型也算是一种比较特殊的引用类型。 3、float f=3.4;是否正确? 答:不正确。3.4是双精度数,将双精度型(double)赋值给浮点型(float)属于下转型(down-casting,也称为窄化)会造成精度损失,因此需要强制类型转换float f =(float)3.4; 或者写成float f =3.4F;。 4、short s1 = 1; s1 = s1 + 1;有错吗?short s1 = 1; s1 += 1;有错吗? 答:对于short s1 = 1; s1 = s1 + 1;由于1是int类型,因此s1+1运算结果也是int 型,需要强制转换类型才能赋值给short型。而short s1 = 1; s1 +=

Java面试题 及答案

Java程序员笔试题 一. Java基础部分 1、一个".java"源文件中是否可以包括多个类(不是内部类)?有什么限制? 可以有多个类,但只能有一个public的类,并且public的类名必须与文件名相一致。 2、Java有没有goto? java中的保留字,现在没有在java中使用 3、说说&和&&的区别。 &和&&都可以用作逻辑与的运算符,&还可以用作位运算符 4、在JA V A中如何跳出当前的多重嵌套循环? break 5、char型变量中能不能存贮一个中文汉字?为什么? 能,char类型的变量占用两个字节 6、使用final关键字修饰一个变量时,是引用不能变,还是引用的对象不能变?使用final关键字修饰一个变量时,是指引用变量不能变,引用变量所指向的对象中的内容还是可以改变的。 7、"=="和equals方法究竟有什么区别? ==操作符用来比较两个变量的值是否相等,equals方法是用于比较两个独立对象的内容是否相同 8、静态变量和实例变量的区别? 实例变量属于某个对象的属性,必须创建了实例对象,静态变量不属于某个实例对象,而是属于类 9、Integer与int的区别 int是基本的数据类型,Integer是java的对象 10、请说出作用域public,private,protected,以及不写时的区别 public公共、private私有、protected受保护的,不写时是friendly 11、面向对象的特征有哪些方面 封装、继承、抽象、多态等4个主要的特征 12、String是最基本的数据类型吗? 不是 13、是否可以继承String类? 不能

java笔试题以及答案详解 一

java笔试题以及答案详解一 一、单项选择题 1.Java是从()语言改进重新设计。 A.Ada B.C++ C.Pasacal D.BASIC 答案:B 2.下列语句哪一个正确() A.Java程序经编译后会产生machine code B.Java程序经编译后会产生byte code C.Java程序经编译后会产生DLL D.以上都不正确 答案:B 3.下列说法正确的有() A.class中的constructor不可省略 B.constructor必须与class同名,但方法不能与class同名 C.constructor在一个对象被new时执行 D.一个class只能定义一个constructor 答案:C 详解:见下面代码,很明显方法是可以和类名同名的,和构造方法唯一的区别就是,构造方法没有返回值。

4.提供Java存取数据库能力的包是() A.java.sql B.java.awt C.https://www.doczj.com/doc/2a8200492.html,ng D.java.swing 答案:A 5.下列运算符合法的是() A.&& B.<> C.if D.:= 答案:A 详解: 6.执行如下程序代码 a=0;c=0; do{ --c; a=a-1;

}while(a>0); 后,C的值是() A.0 B.1 C.-1 D.死循环 答案:C 详解: 7.下列哪一种叙述是正确的() A.abstract修饰符可修饰字段、方法和类 B.抽象方法的body部分必须用一对大括号{ }包住C.声明抽象方法,大括号可有可无 D.声明抽象方法不可写出大括号 答案:D 详解: 8.下列语句正确的是() A.形式参数可被视为local variable B.形式参数可被字段修饰符修饰 C.形式参数为方法被调用时,真正被传递的参数 D.形式参数不可以是对象 答案:A 详解:

Java面试题(带答案)

湖南世杰Java工程师面试题 选择题: 单选题 1,以下java程序代码,执行后的结果是( ) java.util.HashMap map=newjava.util.HashMap(); map.put("name",null); map.put("name","Jack"); System.out.println(map.size()); A: 0 B: null C: 1 D: 2 答案:C 2,执行以下程序后的输出结果是( ) Public class Test { Public static void main(String[] args) { StringBuffer a = new StringBuffer("A"); StringBuffer b = new StringBuffer("B"); operator(a, b); System.out.println(a +","+ b); } Public static void operator(StringBuffer x, StringBuffer y) { x.append(y); y = x;

} } A: A,A B: A,B C: B,B D: AB,B 答案:D 3,关于依赖注入,下列选项中说法错误的是( ) A:依赖注入能够独立开发各组件,然后根据组件间关系进行组装 B:依赖注入使组件之间相互依赖,相互制约 C:依赖注入提供使用接口编程 D:依赖注入指对象在使用时动态注入 答案:B 4,关于spring说法错误的是( ) A: spring是一个轻量级JAVA EE的框架集合 B: spring是“依赖注入”模式的实现 C: 使用spring可以实现声明事务 D: spring提供了AOP方式的日志系统 答案:D 5,要在session对象中保存属性,可以使用以下哪个语句( ) A: session.getAttribute(“key”,”value”) B: session.setAttribute(“key”,”value”) C: session.setAttribute(“key”) D: session.getAttribute(“key”) 答案:B

JAVA面试题及答案

答案: 第一,谈谈final, finally, finalize的区别。 final—修饰符(关键字)如果一个类被声明为final,意味着它不能再派生出新的子类,不能作为父类被继承。因此一个类不能既被声明为abstract的,又被声明为final的。将变量或方法声明为final,可以保证它们在使用中不被改变。被声明为final的变量必须在声明时给定初值,而在以后的引用中只能读取,不可修改。被声明为final的方法也同样只能使用,不能重载。 finally—再异常处理时提供finally 块来执行任何清除操作。如果抛出一个异常,那么相匹配的catch 子句就会执行,然后控制就会进入 finally 块(如果有的话)。 finalize—方法名。Java 技术允许使用finalize() 方法在垃圾收集器将对象从内存中清除出去之前做必要的清理工作。这个方法是由垃圾收集器在确定这个对象没有被引用时对这个对象调用的。它是在Object 类中定义的,因此所有的类都继承了它。子类覆盖finalize()方法以整理系统资源或者执行其他清理工作。finalize() 方法是在垃圾收集器删除对象之前对这个对象调用的。 第二,Anonymous Inner Class (匿名内部类) 是否可以extends(继承)其它类,是否可以implements(实现)interface(接口)? 匿名的内部类是没有名字的内部类。不能extends(继承) 其它类,但一个内部类可以作为一个接口,由另一个内部类实现。 第三,Static Nested Class 和Inner Class的不同,说得越多越好(面试题有的很笼统)。 Nested Class (一般是C++的说法),Inner Class (一般是JAVA的说法)。Java内部类与C++嵌套类最大的不同就在于是否有指向外部的引用上。具体可见http: //https://www.doczj.com/doc/2a8200492.html,/articles/services/view.asp? id=704&page=1 注:静态内部类(Inner Class)意味着1创建一个static内部类的对象,不需要一个外部类对象,2不能从一个static内部类的一个对象访问一个外部类对象

相关主题
文本预览
相关文档 最新文档