论坛首页 入门技术论坛

SCJP认证试题(十二)

浏览 2045 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2008-11-28  
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



Answer: C


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



Answer : C D




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


Answer : D



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


Answer: D



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




Answer: A



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



Answer: D




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


Answer : C


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;


Answer : D





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



Answer : B


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


Answer : D

Explanation :Compilation fails because of an error in line 18 constructor Person() must be present in class Person for compilation to succeed.
论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics