⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 模拟试题_q.txt

📁 包括多年scjp认证考试的很多题库及答案
💻 TXT
字号:
模拟试题(一)


Question No: 1
1. public class test (
2. 	public static void main (String args[]) {
3. 		int i = 0xFFFFFFF1;
4. 		int j = ~i;
5.
6.	}
7. )
j在第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.
 


Question No: 2
Given
1. public class Test{
2. 	public static void main (String args[]) {
3. 		System.out.println (6 ^ 3);
4.	}
5. }
程序的输出为?
 

Question No: 3
Exhibit:
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.println (i.intValue() );
12. 	}
13. }
程序的运行结果?
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 No: 4
Given:
1. public class ConstOver {
2. 	public ConstOver(int x, int y, int z) {
3.	}
4. }
哪两个选项重载了ConstOver构造器? (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) { }
  

Question No 5
Exhibit:
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.
程序运行结果是?
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.
 

Question No 6
Given:
1. int index = 1;
2. boolean[] test = new  boolean[3];
3. boolean foo= test [index];

正确的结果是?
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.
 


Question No 7
Given:
1. int index = 1;
2. int [] foo = new int [3];
3.int bar = foo [index];
4.int baz = bar + index;

正确的结果是?
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.
 

Question No 8
Given:
1. public class foo {
3. 	String s;
2. 	public static void main (String[] args) {
4. 		System.out.println ("s=" + s);
5. 	}
6. }
正确的结果是?

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 non-static String s cannot be referenced from a static context.
E. The code compiles, but a NullPointerException is thrown when toString is called.
 

Question No 9
哪个方法的声明方式强迫它的子类去实现它?

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


Question No 10
Given:
1. abstract class AbstractIt {
2. 	abstract float getFloat();
3. }
4. public class AbstractTest extends AbstractIt {
5. 	private float f1 = 1.0f;
6. 	private float getFloat() {
7.		return f1;
8.	}
9.}

正确结果是?
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.
 

Question No 11
 
1. public class Test{
2. 	static int i=0;
3.	public int aMethod(){
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.println(j);
12.	}
13.}
正确结果是?
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"
  


Question No 12
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 (String args[]) {
15. 		Sub sub = new Sub("Hello");
16. 		System.out.println(sub.i);
17. 	}
18. }
正确结果是?
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"
 

Question No 13
Given:
1. public class ReturnIt {
2. 	returnType methodA(byte x, double y){
3. 	return (short) x/y * 2;
4. 	}
5. }
第二行中methodA的返回类型(returnType)应该是什么?
A. int
B. byte
C. long
D. short
E. float
F. double
   

Question No 14
Given:
3. String foo = "ABCDE";
4. foo.substring(3);
5. foo.concat("XYZ");
6.
打出第六行foo的值
 

Question No 15
哪个方法用来计算42度的cos值最合适?
Which method is an appropriate way to determine the cosine of 42 degrees?
A. Double d = Math.cos(42);
B. Double d = Math.cosine(42);
C. Double d = Math.cos(Math.toRadians(42));
D. Double d = Math.cos(Math.toDegrees(42));
E. Double d = Math.cosine(Math.toRadians(42));
 

Question No 16
需要将一些元素存储到集合中,要求没有重复元素,不排序,可以使用下列哪种集合?
You need to store elements in a collection that guarantees that no duplicates are stored and all elements can be accessed in natural order. Which interface provides that capability?
A. java.util.Map.
B. java.util.Set.
C. java.util.List.
D. java.util.SortedSet.
E. java.util.SortedMap.
F. java.util.Collection.
 


Question No 17
Given:
1. public class IfTest{
2. 	public static void main(String[] args) {
3. 		int x = 3;
4. 		int y = 1;
5. 		if (x = y)
6. 			System.out.println("Not equal");
7. 		else
8. 			System.out.println("Equal");
9.	 }
10. }
正确结论是?
A. The output is "Equal"
B. The output in "Not Equal"
C. An error at line 5 causes compilation to fall.
D. The program executes but does not print a message.


Question No 18
Exhibit:
1. public class Test {
2. 	public static void main(String args[]) {
3. 		int i= 0;
4. 		while (i) {
5. 			if (i==4) {
6. 				break;
7. 			}
8. 			++i;
9. 		}
10.
11. 	}
12. }
第10行的位置i的值是?What is the value of i at line 10?
A. 0
B. 3
C. 4
D. 5
E. The code will not compile.
 

Question No 19
Given:
3. int i= 1, j= 10 ;
4. do {
5. 	if (i++ > --j) continue;
6. } while (i<5);
执行代码和欧,i和j的值是多少? 
A. i = 6 and j= 5
B. i = 5 and j= 5
C. i = 6 and j= 4
D. i = 5 and j= 6
E. i = 6 and j= 6
 

Question No 20
Given:
1. switch (i) {
2. 	default: 
3. 	System.out.println("Hello");
4. }
变量i可以取哪两种数据类型? (Choose Two)
A. char
B. byte
C. float
D. double
E. object
 

Question No 21
Given:
1. public class foo {
2. 	public static void main (String[] args){
3. 		try {return;}
4. 		finally {System.out.println("Finally");}
5. 	}
6. }
正确结论是?
A. The program runs and prints nothing.
B. The program runs and prints "Finally"
C. The code compiles, but an exception is thrown at runtime.
D. The code will not compile because the catch block is missing.


Question No 22
哪个方式创建一个包含五个空字串("")的String数组?
Which correctly create an array of five empty Strings? 
A. String a[] = new String[5]; 
for (int i=0;i<5;a[i++]=""); 
B. String a []={"","","","",""}; 
C. String a[5]; 
D. String [5] a; 
E. String [] a = new String[5]; 
for (int i = 0 ;i<5;a[i++] = null); 



Question No 23
使用操作符">>" 和 ">>>",哪个结论是对的?
 Use the operator ">>" and ">>>". Which statement is true? 
A. 1010 0000 0000 0000 0000 0000 0000 0000 >> 4 give 
   0000 1010 0000 0000 0000 0000 0000 0000 
B. 1010 0000 0000 0000 0000 0000 0000 0000 >> 4 give 
   1111 1010 0000 0000 0000 0000 0000 0000 
C. 1010 0000 0000 0000 0000 0000 0000 0000 >>> 4 give 
   0000 1010 0000 0000 0000 0000 0000 0000 
D. 1010 0000 0000 0000 0000 0000 0000 0000 >>> 4 give 
   1111 1010 0000 0000 0000 0000 0000 0000 


Question No 24
Give following fragment. 
Outer: for(int i=0; i<3; i++) {
	inner:for(int j=0;j<3;j++){ 
		if(j > i) break outer; 
		System.out.println(j + " and " + i); 
	} 
}
输出结果是?Which will be output? 
A. 0 and 0 
B. 0 and 1 
C. 0 and 2 
D. 0 and 3 
E. 1 and 0 
F. 1 and 1 
G. 1 and 2 
H. 1 and 3 
I. 2 and 0
J. 2 and 1 
K. 2 and 2 
L. 2 and 3 


Question No 25
Examine the following code which includes an inner class: 
public final class Test4{ 
	class Inner{ 
		void test(){ 
			if (Test4.this.flag){ 
				sample(); 
			} 
		} 
		
	} 
	private boolean flag = false; 
	public void sample(){ 
		System.out.println("Sample"); 
	} 
	public Test4(){ 
		new Inner().test(); 
	} 
	public static void main(String args[]){ 
		new Test4(); 
	} 
}
正确结论是:
A. Print out "Sample" 
B. Program produces no output but termiantes correctly. 
C. Program does not terminate. 
D. The program will not compile 


Question No 26
 如下语句将得到什么结果?
What is written to the standard output given the following statement: 
System.out.println(4|7); 
Select the right answer: 
A.4 
B.5 
C.6 
D.7 
E.0 


Question No 27
查看下列继承关系Look the inheritance relation: 
 	person 
	   | 
	---------
	|      | 
	man woman 
源文件中有如下语句:In a source of java have the following line: 
person p = new man(); 

下面哪个陈述是对的?What statement are corrected? 
A. The expression is illegal. 
B. Compile corrected but running wrong. 
C. The expression is legal. 
D. Will construct a person?s object. 


Question No 28
Look the inheritance relation: 
	person 
	  | 
	---------
	|      | 
	man woman 
In a source of java have the following line: 
woman w = new man();
What statement are corrected? 
A. The expression is illegal. 
B. Compile corrected but running wrong. 
C. The expression is legal. 
D. Will construct a woman object. 


Question No 29
下面哪个关键字不能被出现在声明或初始化方法变量语句中?
Which can NOT be used in declaring or declaring and initializing an automatic (method local) variable? 
A. final 
B. static 
C. expressions 
D. Constants of non-primitive type 
E. initialized arrays (such as " {"Hello","Good bye"}").


    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -