SCJP考题12

转载 2007年10月13日 15:37:00
1. What will happen when you compile and run this program:
class Test{
pubilc static void main(String[]args){
int length=100;
int[] d=new int[length];
for(int index=0;index<length;index++)
System.out.println(d[index]);
}
}
Select the one right answer.
A. The code will not compile because the int[] array is not declared correctly.
B. The code will compile but will throw an IndexArrayOutOfBoundsException when it runs and nothing will appear in standard output.
C. The code will display the numbers 0 through 99 in the standard output, and then throw an IndexOutOfBoundsException.
D. The code will compile but the println() method will throw a NoSuchMethodException.
E. The code will work fine and display 100 zeroes in the standard output.
正确答案:E
 
 
2. How you can use the escape notation u to set the variable c, declared as a char, to the Unicode character whose value is hex 0X30A0?
Fill in the blank.
正确答案:C=/u30a0;
 
3. Which label name(s) are illegal?
Select all valid answers.
A. here;
B. there;
C. this;
D. that;
E. 2to1odds;
正确答案:C、E
 
4.What will happen when you attempt to compile and run the following program by passing the Test class to the Java interpreter?
class Test{
public static void main(){
System.out println("hello");
}
}
Select the one right answer.
A. The program does not compile because main() is not defined correctly.
B. The program compiles but when you try to run the interpreter complains that it cannot find the main() method it meeds to run.
C. The program compiles but you cannot run it because the class is not declared as public.
D. The program compiles and runs without an error but does not display anything in the standard output.
E.The program compiles and displays "hello" in the standard output when you run it.
正确答案:B
 
 
5.What output is produced by the following program?
class Test{
public static voed main(String args[]){
long size=10;
int[]array=new int[size];
size=20;
System.out.println(array.length);
}
}
Select the one right answer.
A. A compiler error.
B. A runtime error.
C. 10
D. 20
正确答案:A
精解:本题考察的重点是数组大小的指定。
Java 语言中规定用来指定数组长度的数值类型只能是字节型、短整型或整型,而不能是长整型。
 
 
 
 
6. What output is produced by the following program?
class Test{
public static void nain(String args[]){
char[] a1={'u/0030','/u0031'};
System.out.println(a1[1]);
}
}
Select the one right answer.
A. A compiler error
B. A runtime error
C. 30
D. 31
E. 0
F. 1
正确答案: F
 
 
 
7. True or false? All Java applications and applets require a main() method.
Fill in the blank.
正确答案:False
 
8. Show six different ways to express the decimal value 28 as an integral literal.
Fill in the blank.
正确答案:28,034, 0x1c, 0x1C, 0X1c, 0X1C
 
 
9. There are seven characters, at least one of which must be included to indicate a floating point literal. What are they?
Fill in the blank.
正确答案:'E','e', 'F', 'f', 'D', 'd', '.'
 
 
 
 
 
 
 
10. True or false? All member variables and all local ariables are automatically initialized in Java.
Fill in the blank.
正确答案: False
 
 
 
11. Which of the following class definitions defines a legal abstract class?
Select all right answer.
A. class Test {
      abstract void growl();
   }
 
B. abstract Test {
      abstract void growl();
   }
 
C. class abstract Test {
      abstract void growl();
   }
 
D. abstract class Test {
      abstract void growl();
   }
 
E. abstract class Test {
      abstract void growl(){
        System.out.println("growl");
      }
   }
 
 
12. What is the proper way of defining a class named Key so that it cannot be subclassed?
A. class Key{}
B. abstract final class Key{}
C. native class Key{}
D. class Key {final;}
E. final class Key{}
 
 
13. Given the following code:
class Test {
public static void main(String args[]) {
Cellphone cell=new Cellphone();
cell.emergency();
}
}
class Phone{
final void dia1911(){
//code to dial 911 here...
}
}
class CellPhone extends Phone{
void emergency(){
dia1911();
}
}
What will happen when you try to compile and run the Test class?
A. The code will not compile because phone is not also declared as final.
B. The code will not compile because you cannot invoke a final method from a subclass.
C. The code will compile and run fine.
D. The code will compile but will throw a NoSuchMethodException when Test is run.
E. Phone and CellPhone are fine, but Test will not compile because it cannot create as instance of a class that derives from a class defining a final method.
 
 
 
14. What output is produced by the following program? Note that the instance variable named x is declared private
 
class Test {
public static void main(String args[]){
AClass ref1 = new AClass (5);
AClass ref2 = new AClass (10);
ref1.getAnShow(ref2);
}
}
class AClass{
private int x;
AClass(int x){
this.x.=x;
}
void getAndShow(AClass ref){
System.out.print(ref.x+" ");
}
}
Select the one reght answer.
A. compiler error.
B. A runtime error.
C. 10
 
C 来自于同一个类的实例可以相互访问
 
 
 
15. Given the following code:
class Test{
private int m;
public static void fun(){
//some code...
}
}
How can the member variable m be accessible directly in the method fun()?
A. change private int m to protected int m
B. change private int m to public int m
C. change private int m to static int m
D. change private int m to int m
 
C
 
 
 
16. If a member variable of a class can be accessible only by the same package, which modifier should be used?
A. private
B. public
C. protected
D. no modifier
E. final
 
D
 
 
17. Which one of the following is correct to declare a native method?
A. public native void test();
B. public native void test(){}
C. public void native test();
D. public native test(){}
 
A
 
18. Given the following definition of a class:
public class Test{
private float f=1.0f;
int m=12;
static int n=1;
public static void main(String arg[]){
Test t=new Test();
//some code...
}
}
Which of the following usage are legal?
A. t.f
B. this.n
C. Test.m
D. Test.n
 
A, D
 
 
 
19. Given the following class outline:
class Test{
private int x;
//rest of class body
public static void main(String args[]){
//implementation of main method
}
}
Which statement is true?
A. x=2 is a valid assignment in the main() method of class Test.
B. Changing private int x to int x would make x=2 a valid assignment in the main() method of class Test.
C. Changing private int x to public int x would make x=2 a valid assignment in the main() method of class Test.
D. Changing private int x to static int x would make x=2 a valid assignment in the main() method of class Test.
E. Changing class Test to public class Test would make x=2 a valid assignment in the main() method of class Test.
正确答案: D
 
 
 
20. What will be the result when you try to compile and run the following cede?
private class Test{
Test(){
int i=100;
System.out.println(i);
}
}
public class Pri extends Test{
static int i=200;
public static void main(String argv[]){
pri p=new pri();
System.out.println(i);
}
}
Select the one right answer.
A. Error at compile time
B. 200
C. 100 following by 200
D. 100
正确答案: A
 
 
 
 
 
21. What is the result of executing the following code:
class Test{
public static void main(String args[]){
Test t=new Test();
t.test(1.0,2L,3);
}
void test(double a,double b,short c){
System.out.println("1");
}
void test(float a,byte b,byte c){
System.out.println("2");
}
void test(double a, double b, double c){
System.out.println("3");
}
void test(int a,long b,int e){
System.out.println("4");
}
void test(long a, long b, long c){
System.out.println("5");
}
}
Select the one right answer.
A. 1
B. 2
C. 3
D. 4
E. 5
正确答案: C
 
 
22. Given these class definitions:
class Superclass{}
class Subclass1 extends Superclass{}
class Subclass2 extends Superclass{}
And these objects:
Superclass a=new Superclass();
Subclass1 b=new Subclass1();
Subclass2 c=new Subclass2();
Which of the following explains the result of the statement:
b=(Subclass1)c;
Select the one right amswer.
A. Illegal at compile time
B. Legal at compile time but possibly illegal at runtime
C. Definitely legal at runtime
正确答案: A
 
23. Given these class definitions:
class Superclass{}
class Subclass1 extends Superclass{}
And these objects:
Supetclass a=new Superclass();
Suberclass1 b=new Suberclass1();
Which of the following explains the result of the statement:
b=a;
Select the one right amswer.
A. Illegal at compile time
B. Legal at compile time but possibly illegal at runtime
C. Definitely legal at runtime
正确答案: A
 
 
 
24. What output is produced by the following program?
class Test{
public static void main(String args[]){
char x=65;
char y;
y=(char)(2*x);
System.out.println(y);
}
}
Select the one right amswer.
A. A compiler error
B. A runtime error
C. 130
D. ?(symbol for non-printable character)
正确答案: D
 
25. What output is produced by the following program?
class Test{
public static void main(String args[]){
int x;
double y=-10.9;
x=(int)y;
System.out.println(x+" ");
y=10.9;
x=(int)y;
System.out.println(x);
}
}
Select the one right amswer.
A. -11 10
B. -11 11
C. -10 10
D. –10 11
正确答案: C
 
 
26. What output is produced by the following program?
class Test{
public static void main(String args[]){
try{
byte x=5;
byte y=(byte)(x<<2);
System.out.println(y);
}catch(Exception e){
System.out.println("Exception");
}
}
}
Select the one right answer.
A. A compiler error
B. Exception
C. 5
D. 10
E. 15
F. 20
G. 25
正确答案: F
 
 
27. What output is produced by the following program?
class Test{
public static void main(String args[]){
try{
byte x=-32;
byte y=(byte)(x>>>2);
byte z=(byte)(x + y);
System.out.println(y);
}catch(Exception e){
System.out.println("Exception");
}
}
}
Select the one right amswer.
A. A compiler error
B. Exception
C. -4
D. -8
E. -16
F. -32
G. None of the above
正确答案: D
 
 
28. Analyze these two consecutive lines of code:
float f=3.2;
int i=f;
Select all valid answer.
A. this code would not compile
B. this code would compile and i would be set to 3
C. the second line could compile if it were written instead as: int i =(byte)f;
D. the first line could compile if it were written instead as: float f=3.2F;
正确答案: A、C、D
 
 
29. Which of the following lines of code will compile without error?
A. int i=0;
if(i){
System.out.println("Hello");
}
B. boolean b=true;
boolean b2=true;
if(b==b2){
System.out.println("So true");
}
C. int i=1;
int j=2;
if(i==1 || j==2)
System.out.println("OK");
D. int I=1;
int j=2;
if(i==1 &| j==2)
System.out.println("OK");
 
正确答案: B、C
 
 
 
30. Given the following classes which of the following will compile without error?
interface IFace{}
class CFace implements IFace{}
class Base{}
public class Test extends Base{
public static void main(String argv[]){
Test ob=new Test();
Base b=new Base();
Object o1=new Object();
IFace o2=new CFace();
}
}
Select the one right answer.
A. o1=o2;
B. b=ob;
C. ob=b;
D. o1=b;
正确答案: A、B、D
 
 
31. Which of the following are valid statements?
A. System.out.println(1+1);
B. int i=2+'2';
C. byte b=255;
正确答案: A、B
 
 
 

最新驾校模拟考试题库大全接口实现及代码示例

最新驾校模拟考试题库整合API接口,方便调用。采用公安部最新驾校模拟考试题库,可任意选择科目一、科目四模拟考试试题,任选驾照类型,可选择参数为:C1,C2,A1,A2,B1,B2。...
  • juheAPI
  • juheAPI
  • 2015年08月20日 16:29
  • 2033

Sun java认证考试真题答案及部分解析(一)

注:这是一次java大作业,题目比较老,现在java认证考试已经更名为Oracle java认证考试了 1. What gets printed when the following program...
  • archimekai
  • archimekai
  • 2016年05月01日 12:52
  • 1931

2016年RHEL7 :RHCSA试题答案整理

2016年RHEL7 :RHCSA试题答案整理 RHCSA考试: 破解root密码 # e # console=tty0 rd.break # ctrl + x # mount -o remount,...
  • it_taojingzhan
  • it_taojingzhan
  • 2016年04月29日 16:49
  • 3647

SCJP模拟考题140题(310-025)

  • 2011年03月05日 09:13
  • 109KB
  • 下载

SCJP考题解析(简体)---免费

  • 2009年04月13日 23:54
  • 1.38MB
  • 下载

SCJP_6.0认证教战手册考题1-244.pdf

  • 2012年09月09日 20:42
  • 623KB
  • 下载

SCJP考题中的陷阱

  • 2007年05月18日 13:22
  • 45KB
  • 下载

SCJP考题中的陷阱

  • 2008年05月29日 23:16
  • 30KB
  • 下载

最新SCJP考题资料

  • 2009年03月16日 11:01
  • 3.08MB
  • 下载

SCJP考题和模拟器

  • 2010年11月28日 16:28
  • 16.23MB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:SCJP考题12
举报原因:
原因补充:

(最多只允许输入30个字)