SCJP认证试题(十二)

10	public class Hello{
11 String title;
12 int value;
13 public Hello(){
14 title += " world";
15 }
16 public Hello(int value){
17 this.value = value;
18 title = "Hello";
19 Hello();
20 }
21 }



And:
30	Hello c = new Hello(5);
31 System.out.println(c.title);



What is the result ?


A Hello
B Hello World
C Compilation fails
D Hello World 5
E The code runs with no output
F An exception is thrown at runtime


[color=red]Answer: C[/color]


1	class Super{
2 private int a;
3 protected Super(int a){this.a = a;}
4 }
......
11 class Sub extends Super{
12 public Sub(int a){super(a);}
13 public Sub(){this.a = 5;}
14 }


Which two, independently,will allow Sub to compile?(Choose two)


A Change line 2 to :public int a;
B Change line 2 to :protected int a;
C Change line 13 to : public Sub(){this(5);}
D Change line 13 to : public Sub(){super(5);}
E Change line 13 to : public Sub(){super(a);}


[color=red]
Answer : C D
[/color]


11	class converter{
12 public static void main(String[] args){
13 Integer i = args[0];
14 int j = 12;
15 System.out.println("It is "+ (j == i) + " that j == i");
16 }
17 }

What is the result when the programmer attempts to compile the code and run it with the command java Converter 12?


A It is true that j == i
B It is false that j == i
C An exception is thrown at runtime
D Compilation false beacause of an error in line 13


[color=red]Answer : D[/color]


1	public class StringTest1{
2 public static void main(String[] args){
3 String str = "420";
4 str += 42;
5 System.out.println(str);
6 }
7 }


What is the output?


A 42
B 420
C 462
D 42042
E Compilation fails
F An exception is thrown at runtime


[color=red]Answer: D[/color]


11	String test = "a1b2c3";
12 String[] tokens = test.split("\\d");
13 for(String s : tokens) System.out.println(s + "");


What is the result?


A a b c
B 1 2 3
C a1b2c3
D a1 b2 c3
E Compilation fails
F The code runs with no output
G An exception is thrown at runtime


[color=red]Answer: A[/color]


12	String csv = "Sue, 5, true, 3";
13 Scanner scanner = new Scanner(csv);
14 scanner.useDelimiter(",");
15 int age = scanner.nextInt();


What is the result?


A Compilation fails
B After line 15, the value of age is 5
C After line 15, the value of age is 3
D An exception is thrown at runtime


[color=red]
Answer: D[/color]


Given a valid DateFormat object named df, and

16	Date d = new Date(0L);
17 String ds = "December 15, 2004";
18 // insert code here


What update d's value with date represented by ds?


A 18 d=df.parse(ds);
B 18 d=df.getDate(ds);
C 18 try{
19 d = df.parse(ds);
20 }catch(ParseException e){};
D 18 try{
19 d = df.getDate(ds);
20 }catch(ParseException e){};


[color=red]Answer : C[/color]


1	public class Target{
2 private int i = 0;
3 public int addOne(){
4 return ++i;
5 }
6 }

and

1 public class Client{
2 public static void main(String[] args){
3 System.out.println(new Target().addOne());
4 }
5 }


Which changes can you make to Target without affecting Client?


A Line 4 of class Target can be changed to return i++;
B Line 2 of class Target can be changed to private int i =1;
C Line 3 of class Target can be changed to private int addOne(){
D Line 2 of class Target can be changed to private Integer i = 0;


[color=red]Answer : D[/color]


1	class SuperClass{
2 public A getA(){
3 return new A();
4 }
5 }
6 class SubClass extends SuperClass{
7 public B getA(){
8 return new B();
9 }
10 }



Which statement is true?


A Compilation will succeed if A extends B
B Compilation will succeed if B extends A
C Compilation will always fail because of an error in line7
D Compilation will always fail because of an error in line8


[color=red]Answer : B[/color]



11 class Person{
12 String name = "No name";
13 public Person(String nm){name = nm;}
14 }
15
16 class Employee extends Person{
17 String empID = "0000";
18 public Employee(String id){empID = id;}
19 }
20
21 public class EmployeeTest{
22 public static void main(String[] args){
23 Employee e = new Employee("4321")
24 System.out.println(e.empID);
25 }
26 }


What is the result ?

A 4321
B 0000
C An exception is thrown at runtime
D Compilation fails because of an error in line 18


[color=red]Answer : D[/color]

[color=orange]Explanation :Compilation fails because of an error in line 18 constructor Person() must be present in class Person for compilation to succeed.
[/color]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值