1Z0-803 Exam - Java SE 7 Programmer I

certleader.com

Q1. Which is a valid abstract class? 

A. public abstract class Car { 

protected void accelerate(); 

B. public interface Car { 

protected abstract void accelerate(); 

C. public abstract class Car { 

protected final void accelerate(); 

D. public abstract class Car { 

protected abstract void accelerate(); 

E. public abstract class Car { 

protected abstract void accelerate() { 

//more car can do 

}} 

Answer:

Q2. racle 1z0-803 : Practice Test 

j = (3 * ((2+4) + 5)); 

System.out.println("i:"+ i + "\nj":+j); 

What is the result? 

A. Option A 

B. Option B 

C. Option C 

D. Option D 

Answer:

Q3. What is the proper way to defined a method that take two int values and returns their sum as an int value? 

A. int sum(int first, int second) { first + second; } 

B. int sum(int first, second) { return first + second; } 

C. sum(int first, int second) { return first + second; } 

D. int sum(int first, int second) { return first + second; } 

E. void sum (int first, int second) { return first + second; } 

Answer:

Q4. Given the code fragment: 

How many times is 2 printed? 

A. Zero 

B. Once 

C. Twice 

D. Thrice 

E. It is not printed because compilation fails 

Answer:

Q5. ArrayList<Integer> list = new ArrayList<>(1); 

2. list.add(1001); 

3. list.add(1002); 

4. System.out.println(list.get(list.size())); 

What is the result? 

A. Compilation fails due to an error on line 1. 

B. An exception is thrown at run time due to error on line 3 

C. An exception is thrown at run time due to error on line 4 

D. 1002 

Answer:

Q6. The protected modifier on a Field declaration within a public class means that the field 

______________. 

A. Cannot be modified 

B. Can be read but not written from outside the class 

C. Can be read and written from this class and its subclasses only within the same 

package 

D. Can be read and written from this class and its subclasses defined in any package 

Answer:

Q7. Given: 

What code should be inserted? 

A. Option A 

B. Option B 

C. Option C 

D. Option D 

E. Option E 

F. Option F 

Answer:

Q8. Given the code fragment: 

String name = "Spot"; 

int age = 4; 

String str ="My dog " + name + " is " + age; 

System.out.println(str); 

And 

StringBuilder sb = new StringBuilder(); 

Using StringBuilder, which code fragment is the best potion to build and print the following 

string My dog Spot is 4 

A. sb.append("My dog " + name + " is " + age); System.out.println(sb); 

B. sb.insert("My dog ").append( name + " is " + age); System.out.println(sb); 

C. sb.insert("My dog ").insert( name ).insert(" is " ).insert(age); System.out.println(sb); 

D. sb.append("My dog ").append( name ).append(" is " ).append(age); 

System.out.println(sb); 

Answer: AD 

Q9. Given the code fragment: 

What is the result? 

A. 10 8 6 4 2 0 

B. 10 8 6 4 2 

C. An Arithmetic Exception is thrown at runtime 

D. The program goes into an infinite loop outputting: 10 8 6 4 2 0. . . 

E. Compilation fails 

Answer:

Q10. Given: 

What three modifications, made independently, made to class greet, enable the code to compile and run? 

A. line 6 replaced with handy.dandy.keystroke stroke = new KeyStroke ( ); 

B. line 6 replaced with handy.*.KeyStroke = new KeyStroke ( ); 

C. line 6 replaced with handy.dandy.KeyStroke Stroke = new handy.dandy.KeyStroke(); 

D. import handy.*; added before line 1 

E. import handy.dandy.*; added after line 1 

F. import handy.dandy,KeyStroke; added after line 1 

G. import handy.dandy.KeyStroke.typeException(); added before line 1 

Answer: CEF