SCJP认证试题(十二)
10public class Hello{11String title;12int value;13public Hello(){14title += " world";15}16public Hello(int value){17this.value = value;18title = "Hello";19Hello();20}21}And:
30Hello c = new Hello(5);31System.out.println(c.title);
What is the result ?
AHello
BHello World
CCompilation fails
DHello World 5
EThe code runs with no output
FAn exception is thrown at runtime
Answer:C
1class Super{2private int a;3protected Super(int a){this.a = a;}4}......11class Sub extends Super{12public Sub(int a){super(a);}13public Sub(){this.a = 5;}14}
Which two, independently,will allow Sub to compile?(Choose two)
AChange line 2 to :public int a;
BChange line 2 to :protected int a;
CChange line 13 to : public Sub(){this(5);}
DChange line 13 to : public Sub(){super(5);}
EChange line 13 to : public Sub(){super(a);}
Answer : C D
11class converter{12public static void main(String[] args){13Integer i = args;14int j = 12;15System.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?
AIt is true that j == i
BIt is false that j == i
CAn exception is thrown at runtime
DCompilation false beacause of an error in line 13
Answer : D
1public class StringTest1{2public static void main(String[] args){3String str = "420";4str += 42;5System.out.println(str); 6}7}
What is the output?
A42
B420
C462
D42042
ECompilation fails
FAn exception is thrown at runtime
Answer:D
11String test = "a1b2c3";12String[] tokens = test.split("\\d");13for(String s : tokens) System.out.println(s + "");
What is the result?
Aa b c
B1 2 3
Ca1b2c3
Da1 b2 c3
ECompilation fails
FThe code runs with no output
GAn exception is thrown at runtime
Answer:A
12String csv = "Sue, 5, true, 3";13Scanner scanner = new Scanner(csv);14scanner.useDelimiter(",");15int age = scanner.nextInt();
What is the result?
ACompilation fails
BAfter line 15, the value of age is 5
CAfter line 15, the value of age is 3
DAn exception is thrown at runtime
Answer: D
Given a valid DateFormat object named df, and
16Date d = new Date(0L);17String ds = "December 15, 2004";18// insert code here
What update d's value with date represented by ds?
A18 d=df.parse(ds);
B18 d=df.getDate(ds);
C18 try{
19d = df.parse(ds);
20}catch(ParseException e){};
D18 try{
19d = df.getDate(ds);
20}catch(ParseException e){};
Answer : C
1public class Target{2private int i = 0;3public int addOne(){4return ++i;5}6}and 1public class Client{2public static void main(String[] args){3System.out.println(new Target().addOne());4}5}
Which changes can you make to Target without affecting Client?
ALine 4 of class Target can be changed to return i++;
BLine 2 of class Target can be changed to private int i =1;
CLine 3 of class Target can be changed to private int addOne(){
DLine 2 of class Target can be changed to private Integer i = 0;
Answer : D
1class SuperClass{2public A getA(){3return new A();4}5}6class SubClass extends SuperClass{7public B getA(){8return new B();9}10}
Which statement is true?
ACompilation will succeed if A extends B
BCompilation will succeed if B extends A
CCompilation will always fail because of an error in line7
DCompilation will always fail because of an error in line8
Answer : B
11class Person{12String name = "No name";13public Person(String nm){name = nm;}14}1516class Employee extends Person{17String empID = "0000";18public Employee(String id){empID = id;}19}2021public class EmployeeTest{22public static void main(String[] args){23Employee e = new Employee("4321")24System.out.println(e.empID);25}26}
What is the result ?
A4321
B0000
CAn exception is thrown at runtime
DCompilation fails because of an error in line 18
Answer : D
Explanation :Compilation fails because of an error in line 18 constructor Person() must be present in class Person for compilation to succeed.
页:
[1]