JAVA英文面试题
满分:100分(考试时间:1个小时)
guid一选择题(共20题,每题5分,共100分)
●Question 1
What will happen when you attempt to compile and run this code?
abstract class Ba{
abstract public void myfunc() {};
public void another(){
System.out.println("Another method");
}
}
public class Abs extends Ba{
public static void main(String argv[]){
Ba b= new Abs(); //A
b. myfunc(); //B
}
public void myfunc(){
System.out.println("My Func");
}
public void amethod(){
myfunc();
}
davis
}
[1 choice]
1) The code will compile and run, printing out the words "My Func"
2) The compiler will complain error at //A.
3) The compiler will complain error at //B.
4) The compiler will complain error at other position.
●Question 2
What will be the output when the following code is compiled and run (Assuming written inside main)?
String s1 = new String("amit");
System.out.place('m','r'));
System.out.println(s1);
String s3 = "arit";
String s4 = "arit";
String s2 = s1.replace('m','r');
System.out.println(s2 == s3);
System.out.println(s3 == s4);
[1 choice]
A. arit
amit
fal
true
B. arit
clear vision
arit
true
true
C. amit
amit
fal
fal
D. arit思念家乡>lawn mower
arit
true
fal
Question 3
Given:
general
What will happen if you compile/run the following code? class MyClass
{
int x;
MyClass(int i)
{
x = i;
}
public static void main(String args[])
{
MyClass m1 = new MyClass(100);
MyClass m2 = new MyClass(100);
System.out.println(m1==m2);
if(m1.equals(m2))
{
System.out.println("Both are equal");
}
el
{
System.out.println("Both are not equal");
}
}
}
希望英语大赛[1 choice]
A. Compilation error: equals() method was not defined.
B. true Both are equal
C. fal Both are equal.
D. true Both are not equal.
E. fal Both are not equal
●Question 4
Given:
1. public class Foo {
2. public static void main (String [] args) {
3. StringBuffer a = new StringBuffe r (“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? [1 choice]
A. The code comp iles 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 becau “+” cannot be overloaded for StringBu ffer.
●Question 5
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.
●Question 6
Given:
1. public class ConstOver {
2. public ConstOver (int x, int y, int z) {
3. }
4. }
Which two overload the ConstOver constructor? (Choo 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) { }
●Question 7
Given:
1. public class MethodOver {
2. public void tVar (int a, int b, float c) {
3. }
4. }
Which two overload the tVar method? (Choo Two)
A. private void tVar (int a, float c, int b) { }
B. protected void tVar (int a, int b, float c) { }
C. public int tVar (int a, float c, int b) (return a;)
D. public int tVar (int a, int b, float c) (return a;)
E. protected float tVar (int a, int b, float c) (return c;)
●Question 8
public class Test
{
cdfs是什么意思static public void main(String[] args)
{
int counter = 0;
do
{
System.out.println(args[++counter]);
}
while (counter < args.length);
}
}
A. This code caus compile time error.
B. This code compiles without errors and works fine.
C. This code always miss the last parameter pasd to the program.
D. This code compiles without error but will throw a run time exception.
●Question 9
class Parent
{
}
class Child extends Parent
{
public String getChild()
{
String name = "child";
return name;
}
public static void main(String argv[])
{
Parent p = new Child();
//Place your
}
}
What code placed after the comment //Place your will result in calling the getChild() method resulting in the output of the string "child"?
A. System.out.Child());
B. System.out.println(p.name);
C. System.out.println((Child());
D. System.out.println(((Child)p).getChild());
●Question 10
In the following code, What code should be placed after the comment //Here that will print out 5?
public class MyClass
{
annualleave
public static void main(String argv[])
{
int x = 5;sj什么意思
//Here
}
}
[3 choices]
A. System.out.println(x++);