java经典常用笔试题(二)

The following questions have appeared on actual exams. Situational details (ie, names, locations, and quantities) have been changed to avoid copyright infringement. Memorize as many of these questions as possible in the 5 nights prior to your exam. Good luck

1.Given:

1.public class test (
2.  public static void main (String args[])    {
   
3.      int  i = 0xFFFFFFF1;
4.      int  j = ~i;
5.
6.     }
7.)


What is the decimal value of j at line 5?

A.0
B.1
C.14
D.15
E.An error at line 3 causes compilation to fail.
F.An error at line 4 causes compilation to fail.
Answer: C
2.Given:

Integer i = new Integer (42);
Long 1 = new Long (42);
Double d = new Double (42.0);

Which two expressions evaluate to True? (Choose Two)

A.(i ==1)
B.(i == d)
C.(d == 1)
D.(i.equals (d))
E.(d.equals (i))
F.(i.equals (42))
Answer: D,E
3.Click the exhibit button:

1.public class test (    
2.         private static int j = 0;
3.      
4.       private static boolean methodB(int k) (
5.               j += k;
6.               return true;
7.)
8.
9.public static void methodA(int  i) {
   
10.         boolean b:  
11.         b = i < 10 | methodB (4);
12.         b = i < 10 || methodB (8);
13.)
14.
15. public static void main (String args[] }   (
16.             methodA (0);
17.             system.out.printIn(j);
18.           )
19.)

What is the result?

A.The program prints “0”
B.The program prints “4”
C.The program prints “8”
D.The program prints “12”
E.The code does not complete
Answer: B
4.Given:

1.Public class test (
2.    Public static void main (String args[])  (
3.     System.out.printIn (6 ^ 3);
4.   )
5.)

What is the output?

Answer: 5
5.Given:

1.public class Foo {
   
2.  public static void main (String [] args)  {
   
3.     StringBuffer a = new StringBuffer (“A”);
4.     StringBuffer b = new StringBuffer (“B”);
5.    operate (a,b);
6.    system.out.printIn{
   a +,+b};
7.)
8.static void operate (StringBuffer x, StringBuffer y)  {
   
9.          x.append {
   y};
10.          y = x;
11.    )
12.}

What is the result?

A.The code compiles and prints “A,B”.
B.The code compiles and prints “A,A”.
C.The code compiles and prints “B,B”.
D.The code compiles and prints “AB,B”.
E.The code compiles and prints “AB,AB”.
F.The code does not compile because “+” cannot be overloaded for StringBuffer.
Answer: D
6.Click the exhibit button:

1.Public class test (
2.Public static void stringReplace (String text)  (
3.     Text = text.replace (‘j’ , ‘i’);
4.)
5.
6.public static void bufferReplace (StringBuffer text)  (
7.    text = text.append (“C”)
8.)
9.
10.public static void main (String args[]}  (
11.   String textString = new String (“java”);
12.   StringBuffer text BufferString = new StringBuffer (“java”);
13.
14.    stringReplace (textString);
15.    BufferReplace (textBuffer);
16.
17.    System.out.printIn (textString + textBuffer);
18.    }
19. )

What is the output?
Answer: JavaJavaC
7.Click the Exhibit button:

1.public class test {
   
2.     public static void add3 (Integer i) }
3.    int val = i.intvalue ( );
4.          val += 3;
5.          i = new Integer (val);
6.     }
7.
8.  public static void main (String args [ ] )  {
   
9.   Integer  i = new Integer (0);
10.    add3 (i);
11.     system.out.printIn (i.intvalue ( )  );
12.  }
13.)

What is the result?

A.Compilation will fail.
B.The program prints “0.
C.The program prints “3.
D.Compilation will succeed but an exception will be thrown at line 3.
Answer: B
8.Given:

1.public class ConstOver {
   
2.  public ConstOver (int x, int y, int z)  {
   
3.     }
4.}

Which two overload the ConstOver constructor? (Choose Two)

A.ConstOver ( ) {
    }
B.Protected int ConstOver ( ) {
    }
C.Private ConstOver (int z, int y, byte x) {
    }
D.public Object ConstOver (int x, int y, int z) {
    }
E.public void ConstOver (byte x, byte y, byte z) {
    }
Answer: A,C
9.Given:

1.public class MethodOver  {
   
2.    public void setVar (int a, int b, float c)  {
   
3.    }
4.}

Which two overload the setVar method? (Choose Two)

A.private void setVar (int a, float c, int b)  {
    }
B.protected void setVar (int a, int b, float c) {
    }
C.public int setVar (int a, float c, int b) (return a;)
D.public int setVar (int a, int b, float c) (return a;)
E.protected float setVar (int a, int b, float c) (return c;)
Answer: A,C
10.Given:

1.class BaseClass {
   
2.   Private float x = 1.0f ;
3.    protected float getVar ( ) ( return x;)
4.}
5.class Subclass extends BaseClass (
6.      private float x = 2.0f;
7.      //insert code here
8.)

Which two are valid examples of method overriding? (Choose Two)

A.float getVar ( ) {
    return x;}
B.public float getVar ( ) {
    return x;}
C.float double getVar ( ) {
    return x;}
D.protected float getVar ( ) {
    return x;}
E.public float getVar (float f ) {
    return f;}
Answer: B,D
11.Which two demonstrate an “is a” relationship? (Choose Two)

A.public interface Person {
    }
public class Employee extends Person {
    }
B.public interface Shape {
    }
public class Employee extends Shape {
    }
C.public interface Color {
    }
public class Employee extends Color {
    }
D.public class Species {
    }
public class Animal (private Species species;)
E.interface Component {
    }
Class Container implements Component (
         Private Component[ ] children;
)
Answer: D,E
12.Which statement is true?

A.An anonymous inner class may be declared as final
B.An anonymous inner class can be declared as private
C.An anonymous inner class can implement multiple interfaces
D.An anonymous inner class can access final variables in any enclosing scope
E.Construction of an instance of a static inner class requires an instance of the enclosing outer class.
Answer: D
13.Given:

1.package foo;
2.
3.public class Outer (
4.   public static class Inner (
5.   )
6.)

Which statement is true?

A.An instance of the Inner class can be constructed with “new Outer.Inner ()”
B.An instance of the inner class cannot be constructed outside of package foo
C.An instance of the inner class can only be constructed from within the outer class
D.From within the package bar, an instance of the inner class can be constructed with “new inner()”
Answer: A
14.Click the exhibit button:


1.public class enclosingone (
2.public class insideone{
   }
3.)
4.public class inertest(
5.public static void main (string[]args)(
6.enclosingone eo= new enclosingone ();
7.//insert code here
8.)9.)

Which statement at line 7 constructs an instance of the inner class?

A.InsideOnew ei= eo.new InsideOn();
B.Eo.InsideOne ei = eo.new InsideOne();
C.InsideOne ei = EnclosingOne.new InsideOne();
D.EnclosingOne.InsideOne ei = eo.new InsideOne();
Answer: D
15.Click the exhibit button:


1.interface foo {
   
2.int k = 0;
3.]
4.
5.public class test implements Foo (
6.public static void main(String args[]) (
7.int i;
8.Test test = new test ();
9.i= test.k;
10.i= Test.k;
11.i= Foo.k;
12.)
13.)
14.    

What is the result?

A.Compilation succeeds.
B.An error at line 2 causes compilation to fail.
C.An error at line 9 causes compilation to fail.
D.An error at line 10 causes compilation to fail.
E.An error at line 11 causes compilation to fail.
Answer: A
16. Given:

1.//point X
2.public class foo (
3.public static void main (String[]args) throws Exception {
   
4.printWriter out = new PrintWriter (new
5.java.io.outputStreamWriter (System.out), true;
6.out.printIn(“Hello”);
7.}
8.)

Which statement at PointX on line 1 allows this code to compile and run?

A.import java.io.PrintWriter;
B.include java.io.PrintWriter;
C.import java.io.OutputStreamWriter;
D.include java.io.OutputStreamWriter;
E.no statement is needed.
Answer: A
17.Which two statements are reserved words in Java? (Choose Two)

A.run
B.import
C.default
D.implement
Answer: B,C
18.Which three are valid declarations of a float? (Choose Three)

A.float foo = -1;
B.float foo = 1.0;
C.float foo = 42e1;
D.float foo = 2.02f;
E.float foo = 3.03d;
F.float foo = 0x0123;
Answer: A,D,F	
19.Given:

8.   int index = 1;
9.   boolean[] test = new Boolean[3];
10.boolean foo= test [index];

What is the result?

A.foo has the value of 0
B.foo has the value of null
C.foo has the value of true
D.foo has the value of false
E.an exception is thrown
F.the code will not compile
Answer: D
20.Given:

1.public class test(
2.public static void main(string[]args){
   
3.string foo = args [1];
4.string foo = args [2];
5.string foo = args [3];
6.}
7.}

And the command line invocation:
Java Test red green blue

What is the result?

A.baz has the value of “”
B.baz has the value of null
C.baz has the value of “red”
D.baz has the value of “blue”
E.bax has the value of “green”
F.the code does not compile
G.the program throws an exception
Answer: F
21.Given:

8.int index = 1;
9.int [] foo = new int [3];
10.int bar = foo [index];
11.int baz = bar + index;

What is the result?

A.baz has the value of 0
B.baz has the value of 1
C.baz has the value of 2
D.an exception is thrown
E.the code will not compile
Answer: B
22.Given:

1.public class foo {
   
2.public static void main (String[]args) {
   
3.String s;
4.system.out.printIn (“s=+ s);
5.}
6.}

What is the result?

A.The code compiles and “s=” is printed.
B.The code compiles and “s=null” is printed.
C.The code does not compile because string s is not initialized.
D.The code does not compile because string s cannot be referenced.
E.The code compiles, but a NullPointerException is thrown when toString is called.
Answer: C
23.Which will declare a method that forces a subclass to implement it?

A.Public double methoda();
B.Static void methoda (double d1) {
   }
C.Public native double methoda();
D.Abstract public void methoda();
E.Protected void methoda (double d1){
   }
Answer: D
24.You want subclasses in any package to have access to members of a superclass. Which is the most restrictive access modifier that will accomplish this objective?

A.Public
B.Private
C.Protected
D.Transient
E.No access modifier is qualified
Answer: C
25.Given:

1.abstract class abstrctIt {
   
2.abstract float getFloat ();
3.)
4.public class AbstractTest extends AbstractIt {
   
5.private float f1= 1.0f;
6.private float getFloat () {
   return f1;}
7.}

What is the result?

A.Compilation is successful.
B.An error on line 6 causes a runtime failure.
C.An error at line 6 causes compilation to fail.
D.An error at line 2 causes compilation to fail.
Answer: C
26.Click the exhibit button:


1.public class test(
2.public int aMethod()[
3.static int i=0;
4.i++;
5.return I;
6.)
7.public static void main (String args[]){
   
8.test test = new test();
9.test.aMethod();
10.int j = test.aMethod();
11.System.out.printIn(j);
12.]
13.}
   

What is the result?

A.Compilation will fail.
B.Compilation will succeed and the program will print “0.
C.Compilation will succeed and the program will print “1.
D.Compilation will succeed and the program will print “2.
Answer: A
27.Given:

1.class super {
   
2.public float getNum() {
   return 3.0f;}
3.)
4.
5.public class Sub extends Super {
   
6.
7.)

Which method, placed at line 6, will cause a compiler error?

A. public float getNum()   {
   return 4.0f; }
B. public void getNum ()  {
    }
C. public void getNum (double d)   {
    }
D. public double getNum (float d) {
   retrun 4.0f; }
Answer: B
28.Which declaration prevents creating a subclass of an outer class?

A.static class FooBar{
   }
B.private class FooBar{
   }
C.abstract public class FooBar{
   }
D.final public class FooBar{
   }
E.final abstract class FooBar{
   }
Answer: D
29.Given:

1.byte [] arry1, array2[];
2.byte array3 [][];
3.byte[][] array4;

If each array has been initialized, which statement will cause a compiler error?

A.array2 = array1;
B.array2 = array3;
C.array2 = array4;
D.both A and B
E.both A and C
F.both B and C
Answer: F
30.Click the exhibit button:


1.class super (
2.public int I = 0;
3.
4.public super (string text) (
5.I = 1
6.)
7.  )
8.  
9.public class sub extends super (
10.public sub (string text)   (
11.i= 2
12.)
13.
14.public static void main (straing args[])   (
15.sub sub = new sub (“Hello”);
16.system.out. PrintIn(sub.
  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
常用java笔试题,n多年都在用. 1、面向对象的特征有哪些方面 1.抽象: 2.继承: 3.封装: 4. 多态性: 2、String是最基本的数据类型吗? 基本数据类型包括byte、int、char、long、float、double、boolean和short。 java.lang.String类是final类型的,因此不可以继承这个类、不能修改这个类。为了提高效率节省空间,我们应该用StringBuffer类 3、int 和 Integer 有什么区别 Java 提供两种不同的类型:引用类型和原始类型(或内置类型)。Int是java的原始数据类型,Integer是java为int提供的封装类。Java为每个原始类型提供了封装类。 原始类型封装类 booleanBoolean charCharacter byteByte shortShort intInteger longLong floatFloat doubleDouble 引用类型和原始类型的行为完全不同,并且它们具有不同的语义。引用类型和原始类型具有不同的特征和用法,它们包括:大小和速度问题,这种类型以哪种类型的数据结构存储,当引用类型和原始类型用作某个类的实例数据时所指定的缺省值。对象引用实例变量的缺省值为 null,而原始类型实例变量的缺省值与它们的类型有关。 *., 多线程有几种表示方法,都是什么?同步有几种实现方法,都是什么? 多线程有两种实现方法,分别是继承Thread类与实现Runnable接口 同步的实现方面有两种,分别是synchronized,wait与notify 4、String 和StringBuffer的区别 JAVA平台提供了两个类:String和StringBuffer,它们可以储存和操作字符串,即包含多个字符的字符数据。这个String类提供了数值不可改变的字符串。而这个StringBuffer类提供的字符串进行修改。当你知道字符数据要改变的时候你就可以使用StringBuffer。典型地,你可以使用StringBuffers来动态构造字符数据。 5、运行时异常与一般异常有何异同?

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值