java equalwith_Java笔试题

本文涉及Java编程的各个方面,包括类的抽象方法、构造器、修饰符、异常处理、内存管理、布局管理器、线程、事件处理、集合框架、输入输出流、接口、方法重写和并发等概念。通过一系列编程示例,详细阐述了编译、运行时可能出现的结果以及相关API的使用。
摘要由CSDN通过智能技术生成

2015-05-02 06:30:01

阅读( 2 )

Question 1)

What will happen when you attempt to compile and run this code?

当试图编译并运行下面程序时会出现什么结果?

abstract class Base{

abstract public void myfunc();

public void another(){

System.out.println(“Another method”);

}

}

public class Abs extends Base{

public static void main(String argv[]){

Base a = new Abs();

a. another ();

}

public void myfunc(){

System.out.println(“My Func”);

}

public void another (){

myfunc();

}

}

1) The code will compile and run, printing out the words “My Func”

代码编译、运行并打印出“My Func”

2) The compiler will complain that the Base class has non abstract methods

编译器会报怨Base class有非抽象方法

3) The code will compile but complain at run time that the Base class has non abstract methods

代码可以编译通过,但运行时会报Base class 有非抽象方法

4) The compiler will complain that the method myfunc in the base class has no body

编译器会报Base class没有方法体

Answer to Question 1

——————————————————————————–

Question 2)

What will happen when you attempt to compile and run this code?

当试图编译并运行下面程序时会出现什么结果?

public class MyMain{

public static void main(String argv){

System.out.println(“Hello cruel world”);

}

}

1) The compiler will complain that main is a reserved word and cannot be used for a class

编译器报怨main属于保留字而不能在一个class中使用

2) The code will compile and when run will print out “Hello cruel world”

代码将编译、运行并输出“Hello cruel world”

3) The code will compile but will complain at run time that no constructor is defined

代码编译通过但运行时报没有定义构造方法

4) The code will compile but will complain at run time that main is not correctly defined

代码编译通过但运行时报main方法没有正确定义

Answer to Question 2

——————————————————————————–

Question 3)

Which of the following are Java modifiers?

下面哪些是java修饰符?

1) public

2) private

3) friendly

4) transient

5) vagrant

Answer to Question 3

——————————————————————————–

Question 4)

What will happen when you compile and run it.?

当编译并运行下面程序时会出现什么结果?

public class MyAr{

public static void main(String argv[]){

int[] i = new int[5];

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

}

}

1) An error at compile time

编译出错

2) An error at run time

运行出错

3) The value 0 will be output

输出0

4) The string “null” will be output

输出“null”

Answer to Question 4

——————————————————————————–

Question 5)

What best describes the appearance of an application with the following code?

下面哪个能最恰当的描述这个程序的运行效果?

import java.awt.*;

public class FlowAp extends Frame{

public static void main(String argv[]){

FlowAp fa=new FlowAp();

fa.setSize(400,300);

fa.setVisible(true);

}

FlowAp(){

add(new Button(“One”));

add(new Button(“Two”));

add(new Button(“Three”));

add(new Button(“Four”));

}//End of constructor

}//End of Application

1)A Frame with buttons marked One to Four placed on each edge.

窗体的每个边上依次放置按钮One到按钮Four

2) A Frame with buttons marked One to four running from the top to bottom

按钮从上到下依次摆放在窗体上上

3) A Frame with one large button marked Four in the Centre

按钮Four作为一个大的按钮放在窗体的中间

4) An Error at run time indicating you have not set a LayoutManager

运行出错,因为没有设置LayoutManager布局管理器

Answer to Question 5

——————————————————————————–

Question 6)

How do you change the current layout manager for a container

如何改变容器的布局管理器?

1) Use the setLayout method

采用setLayout方法

2) Once created you cannot change the current layout manager of a container

一旦产生,你无法改变容器当前的布局管理器

3) Use the setLayoutManager method

采用setLayoutManager方法

4) Use the updateLayout method

采用updateLayout方法

Answer to Question 6)

——————————————————————————–

Question 7)

What most closely matches the appearance when this code runs?

当运行下面代码时,哪个最接近程序的结果?

import java.awt.*;

public class CompLay extends Frame{

public static void main(String argv[]){

CompLay cl = new CompLay();

}

CompLay(){

Panel p = new Panel();

p.setBackground(Color.pink);

p.add(new Button(“One”));

p.add(new Button(“Two”));

p.add(new Button(“Three”));

add(“South”,p);

setLayout(new FlowLayout());

setSize(300,300);

setVisible(true);

}

}

1) The buttons will run from left to right along the bottom of the Frame

按钮沿着窗体的底部从左到右摆放

2) The buttons will run from left to right along the top of the frame

按钮沿着窗体的顶部从左到右摆放

3) The buttons will not be displayed

所有按钮将不显示

4) Only button three will show occupying all of the frame

只有按钮3显示并占据整个窗体

Answer to Question 7)

——————————————————————————–

Question 8)

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

当编译并运行下面程序时会发生什么结果?

public class Bground extends Thread{

public static void main(String argv[]){

Bground b = new Bground();

b.run();

}

public void start(){

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

System.out.println(“Value of i = ” + i);

}

}

}

1) A compile time error indicating that no run method is defined for the Thread class

编译错误,指明run方法没有定义

2) A run time error indicating that no run method is defined for the Thread class

运行错误,指明run方法没有定义

3) Clean compile and at run time the values 0 to 9 are printed out

编译通过并输出0到9

4) Clean compile but no output at runtime

编译通过但无输出

Answer to Question 8)

——————————————————————————-

Question 9)

For a class defined inside a method, what rule governs access to the variables of the enclosing method?

对于定义在方法内部的类来说,它可以访问该方法的哪些变量?

1) The class can access any variable

可以访问任何变量

2) The class can only access static variables

只能访问静态变量

3) The class can only access transient variables

只能访问transient变量

4) The class can only access final variables

只能访问final常量

Answer to Question 9)

——————————————————————————–

Question 10)

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

当编译并运行下面程序时会发生什么结果?

public class Hope{

public static void main(String argv[]){

Hope h = new Hope();

}

protected Hope(){

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

System.out.println(i);

}

}

}

1) Compilation error: Constructors cannot be declared protected

编译错误,构造方法不能被声明为protected

2) Run time error: Constructors cannot be declared protected

运行错误,构造方法不能被声明为protected

3) Compilation and running with output 0 to 10

编译并运行输出0到10

4) Compilation and running with output 0 to 9

编译并运行输出0到9

Answer to Question 10)

——————————————————————————–

Question 11)

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

当编译并运行下面程序时会发生什么结果?

public class MySwitch{

public static void main(String argv[]){

MySwitch ms= new MySwitch();

ms.amethod();

}

public void amethod(){

int k=10;

switch(k){

default: System.out.println(“This is the default output”);

break;

case 10:

System.out.println(“ten”);

case 20:

System.out.println(“twenty”);

break;

}

}

}

1) None of these options

无解

2) Compile time error target of switch must be an integral type

编译错误,switch要求是integral类型

3) Compile and run with output “This is the default output”

编译并运行输出“This is the default output”

4) Compile and run with output of the single line “ten”

编译并运行输出“ten”

Answer to Question 11)

——————————————————————————–

Question 12)

Which of the following is the correct syntax for suggesting that the JVM performs garbage collection

JVM执行垃圾回收的正确语法是什么?

1) System.free();

2) System.setGarbageCollection();

3) System.out.gc();

4) System.gc();

Answer to Question 12)

——————————————————————————–

Question 13)

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

当编译并运行下面程序时会发生什么结果?

public class As{

int i = 10;

int j;

char z= 1;

boolean b;

public static void main(String argv[]){

As a = new As();

a.amethod();

}

public void amethod(){

System.out.println(j);

System.out.println(b);

}

}

1) Compilation succeeds and at run time an output of 0 and false

编译并运行输出0和false

2) Compilation succeeds and at run time an output of 0 and true

编译并运行输出0和true

3) Compile time error b is not initialized

编译错误报变量b没有初始化

4) Compile time error z must be assigned a char value

编译错误,变量z必须赋予一个字符

Answer to Question 13)

——————————————————————————–

Question 14)

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

当编译并运行下面程序时会发生什么结果?

public class StrEq{

public static void main(String argv[]){

StrEq s = new StrEq();

}

private StrEq(){

String s = “Marcus”;

String s2 = new String(“Marcus”);

if(s == s2){

System.out.println(“we have a match”);

}else{

System.out.println(“Not equal”);

}

}

}

1) Compile time error caused by private constructor

编译错误报构造方法私有化

2) Output of “we have a match”

输出“we have a match”

3) Output of “Not equal”

输出“Not equal”

4) Compile time error by attempting to compare strings using ==

编译错误,由于采用了==作比较

Answer to Question 14)

——————————————————————————–

Question 15)

What will happen when you attempt to compile and run this program

当编译并运行下面程序时会发生什么结果?

public class Outer{

public String name = “Outer”;

public static void main(String argv[]){

Inner i = new Inner();

i.showName();

}//End of main

private class Inner{

String name =new String(“Inner”);

void showName(){

System.out.println(name);

}

}//End of Inner class

}

1) Compile and run with output of “Outer”

编译并运行输出“Outer”

2) Compile and run with output of “Inner”

编译并运行输出“Inner”

3) Compile time error because Inner is declared as private

编译错误,Inner被声明为private

4) Compile time error because of the line creating the instance of Inner

编译错误,由于产生Inner实例一行出错(Inner i = new Inner();)

Answer to Question to 15

——————————————————————————–

Question 16)

What will happen when you attempt to compile and run this code

当编译并运行下面程序时会发生什么结果?

//Demonstration of event handling

import java.awt.event.*;

import java.awt.*;

public class MyWc extends Frame implements WindowListener{

public static void main(String argv[]){

MyWc mwc = new MyWc();

}

public void windowClosing(WindowEvent we){

System.exit(0);

}//End of windowClosing

public void MyWc(){

setSize(300,300);

setVisible(true);

}

}//End of class

1) Error at compile time

编译出错

2) Visible Frame created that that can be closed

窗体可见并且可以关闭

3) Compilation but no output at run time

编译通过但无输出

4) Error at compile time because of comment before import statements

由于import前面有注释导致编译出错

Answer to Question 16)

——————————————————————————–

Question 17)

Which option most fully describes will happen when you attempt to compile and run the following code

当编译和运行下面程序时,哪项描述可以最准确的表达发生了什么事情?

public class MyAr{

public static void main(String argv[]) {

MyAr m = new MyAr();

m.amethod();

}

public void amethod(){

static int i;

System.out.println(i);

}

}

1) Compilation and output of the value 0

编译并输出0

2) Compile time error because i has not been initialized

编译错误,因为i没有初始化

3) Compilation and output of null

编译并输出null

4) Compile time error

编译错误

Answer to Question 17)

——————————————————————————–

Question 18)

Which of the following will compile correctly

下面哪一个编译正确?

1) short myshort = 99S;

2) String name = ‘Excellent tutorial Mr Green’;

3) char c = 17c;

4)int z = 015;

Answer to Question 18)

——————————————————————————–

Question 19)

Which of the following are Java key words

哪些是java关键字?

1)double

2)Switch

3)then

4)instanceof

Answer to Question 19)

——————————————————————————–

Question 20)

What will be output by the following line?

下面程序的输出是什么?

System.out.println(Math.floor(-2.1));

1) -2

2) 2.0

3) -3

4) -3.0

Answer to Question 20)

——————————————————————————–

Question 21)

Given the following main method in a class called Cycle and a command line of

看下面的Cycle程序,执行下面的命令

java Cycle one two

what will be output?

结果是什么?

public static void main(String bicycle[]){

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

}

1) None of these options

2) cycle

3) one

4) two

Answer to Question 21)

——————————————————————————–

Question 22)

Which of the following will compile without error

下面哪些编译正确?

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{}

Answer to Question 3

——————————————————————————–

Question 23)

Which of the following statements are true?

下面哪个叙述是正确的?

1) At the root of the collection hierarchy is a class called Collection

Collection类是集合类的根

2) The collection interface contains a method called enumerator

Collection接口包含一个方法enumerator

3) The iterator method returns an instance of the Vector class

Iterator方法返回Vector类的一个实例

4) The set interface is designed for unique elements

set接口用于存放不同元素的

Answer to Question 23)

——————————————————————————–

Question 24)

Given the following code

考虑下面的代码

class Base{}

public class MyCast extends Base{

static boolean b1=false;

static int i = -1;

static double d = 10.1;

public static void main(String argv[]){

MyCast m = new MyCast();

Base b = new Base();

//Here

}

}

Which of the following, if inserted at the comment //Here will allow the code to compile and run without error

下面哪些代码,当被插入//here所指地方时,编译和运行不会出错

1) b=m;

2) m=b;

3) d =i;

4) b1 =i;

Answer to Question 24)

——————————————————————————–

Question 25)

Which of the following statements about threading are true

下面关于线程的叙述哪些是正确的?

1) You can only obtain a mutually exclusive lock on methods in a class that extends Thread or implements runnable

你只能在继承Thread或者实现runnable接口的类的方法上获取互斥锁

2) You can obtain a mutually exclusive lock on any object

你可以在任何对象上获得互斥锁

3) A thread can obtain a mutually exclusive lock on a synchronized method of an object

一个线程可以获得一个synchronized同步方法上的互斥锁

4) Thread scheduling algorithms are platform dependent

线程调度算法跟平台有关

Answer to Question 25)

——————————————————————————–

Question 26)

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

当编译和运行下面代码时会发生什么?

int Output=10;

boolean b1 = false;

if((b1==true) && ((Output+=10)==20)){

System.out.println(“We are equal “+Output);

}else

{

System.out.println(“Not equal! “+Output);

}

1) Compile error, attempting to peform binary comparison on logical data type

编译错误,因为在逻辑数据类型上作比较

2) Compilation and output of “We are equal 10″

编译并输出”We are equal 10″

3) Compilation and output of “Not equal! 20″

编译并输出”Not equal! 20″

4) Compilation and output of “Not equal! 10″

编译并输出”Not equal! 10″

Answer to Question 26)

——————————————————————————–

Question 27)

What will be output by the following line of code?

这行代码输出是什么?

System.out.println(010|4);

1) 14

2) 0

3) 6

4) 12

Answer

to Question 27)

——————————————————————————–

Question 28)

Which of the following will compile without error?

下面哪句代码编译没有错误?

1) File f = new File(“/”,”autoexec.bat”);

2) DataInputStream d = new

DataInputStream(System.in);

3) OutputStreamWriter o = new

OutputStreamWriter(System.out);

4) RandomAccessFile r = new

RandomAccessFile(“OutFile”);

Answer

to Question 28)

——————————————————————————–

Question 29)

Given the folowing classes which of the following will compile without

error?

下面哪个编译没有错误?

interface IFace{}

class CFace implements IFace{}

class Base{}

public class ObRef extends Base{

public static void main(String argv[]){

ObRef ob = new ObRef();

Base b = new Base();

Object o1 = new Object();

IFace o2 = new CFace();

}

}

1)o1=o2;

2)b=ob;

3)ob=b;

4)o1=b;

Answer

to Question 29)

——————————————————————————–

Question 30)

Given the following code what will be the output?

下面代码的输出结果是什么?

class ValHold{

public int i = 10;

}

public class ObParm{

public static void main(String argv[]){

ObParm o = new ObParm();

o.amethod();

}

public void amethod(){

int i = 99;

ValHold v = new ValHold();

v.i=30;

another(v,i);

System.out.println(v.i);

}//End of amethod

public void another(ValHold v, int i){

i=0;

v.i = 20;

ValHold vh = new ValHold();

v = vh;

System.out.println(v.i+ ” “+i);

}//End of another

}

1) 10,0, 302) 20,0,303) 20,99,304) 10,0,20

Answer

to Question 30)

——————————————————————————–

Question 31)

Given the following class definition, which of the following methods could be

legally placed after the comment//Here

下面哪个方法可以放在注释//here处?

public class Rid{

public void amethod(int i, String s){}

//Here

}

1)public void amethod(String s, int i){}

2)public int amethod(int i,

String s){}

3)public void amethod(int i, String mystring){}

4) public void Amethod(int i, String s) {}

Answer

to Question 31)

——————————————————————————–

Question 32)

Given the following class definition which of the following can be legally

placed after the comment line//Here ?

下面哪个方法可以放在注释//here处?

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

}

}

1)MyOver m = new MyOver();

2)super();

3)this(“Hello”,10);

4)Base b = new Base(10);

Answer

to Question 32)

——————————————————————————–

Question 33)

Given the following class definition, which of the following statements would

be legal after the comment //Here

下面哪个方法可以放在注释//here处?

class InOut{

String s= new String(“Between”);

public void amethod(final int iArgs){

int iam;

class Bicycle{

public void sayHello(){

//Here

}//End of bicycle class

}

}//End of amethod

public void another(){

int iOther;

}

}

1)System.out.println(s);

2) System.out.println(iOther);

3) System.out.println(iam);

4) System.out.println(iArgs);

Answer

to Question 33)

——————————————————————————–

Question 34)

Which of the following are methods of the Thread class?

哪些是Thread类中的方法?

1) yield()2) sleep(long msec)3) go()4) stop(),wait(),wait(100),notify(),notifyAll()

Answer

to Question 34)

——————————————————————————–

Question 35)

Which of the following methods are members of the Vector class and allow you

to input a new element

下面哪些是Vector类中的方法并且可以插入新的元素进去?

1) addElement2) insert3) append4) addItem

Answer

to Question 35)

——————————————————————————–

Question 36)

Which of the following statements are true?

下面哪些为真?

1) Adding more classes via import statements will cause a performance

overhead, only import classes you actually use.

添加很多的import语句会导致性能问题,只需倒入实际需要的就行

2) Under no circumstances can a class be defined with the private modifier

任何情况下,类都不能被private修饰

3) A inner class may under some circumstances be defined with the protected modifier

内部类在某些情况下可以被protected修饰

4) An interface cannot be instantiated

接口不能实例化

Answer 36)

——————————————————————————–

Question 37)

Which of the following are correct event handling methods

下面哪些是正确的事件处理方法?

1) mousePressed(MouseEvent e){}

2) MousePressed(MouseClick e){}

3) functionKey(KeyPress k){}

4) componentAdded(ContainerEvent e){}

Answer 37)

——————————————————————————–

Question 38)

Which of the following are methods of the Collection interface?

下面哪些是接口Collection中的方法?

1) iterator

2) isEmpty

3) toArray

4) setText

Answer 38)

——————————————————————————–

Question 39)

Which of the following best describes the use of the synhronized keyword?

下面哪些是正确的描述了关键字synhronized

1) Allows two process to run in paralell but to communicate with each

other

允许两个进程并行运行但其之间相互通信

2) Ensures only one thread at a time may access a method or

object

保证任何时候只有一个线程访问一个方法或对象

3) Ensures that two or more processes will start and end at the same

time

保证两个或多个进程同时启动和结束

4) Ensures that two or more Threads will start and end at the same

time

保证两个或多个线程同时启动和结束

Answer 39)

——————————————————————————–

Question 40)

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

下面哪些编译时没有警告或错误?

1) float f=1.3;

2) char c=”a”;

3) byte b=257;

4) boolean b=null;

5) int i=10;

Answer 40)

——————————————————————————–

分享给朋友:

亲~ 如果您有更好的答案 可在评论区发表您独到的见解。

您想查看更多的信息:

面试题

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值