0% found this document useful (0 votes)
78 views

Mock Exam 3 For SCJP 6

This summarizes a mock exam for the Sun Certification for Java Programmer (SCJP) 6 exam. The mock exam has 29 multiple choice questions to model the real exam, which may be slightly harder and have 60 questions instead. To pass the real exam, a score of at least 58.33% correct answers is needed. The real exam may also contain more programmatic questions asking about what will happen when specific code is compiled.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
78 views

Mock Exam 3 For SCJP 6

This summarizes a mock exam for the Sun Certification for Java Programmer (SCJP) 6 exam. The mock exam has 29 multiple choice questions to model the real exam, which may be slightly harder and have 60 questions instead. To pass the real exam, a score of at least 58.33% correct answers is needed. The real exam may also contain more programmatic questions asking about what will happen when specific code is compiled.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

Mock Exam 3 for SCJP 6

The mock exam is modeled on the Sun Certification for Java Programmer SCJP
6 exam. The exam has 29 questions. The real exam may be a little tougher than
this. You need to score 58.33% correct answers to clear the real exam.

a. The real exam will be tougher than this.


b. The real exam will have 60 questions. This one has only 29
c. The real exam would have more programmatic questions. Questions of the
type - "what will happen when this code is compiled".

1. Which of the following are Java keywords? Select the three correct
answers.
A. external
B. implement
C. throw
D. void
E. integer
F. private
G. synchronize
H. unsigned

2. Which of the following are legal definitions of the main method that can
be used to execute a class. Select the one correct answer.
A. public void main(String args)
B. public static int main(String args[])
C. public static void main(String args[])
D. static public void MAIN(String args[])
E. public static void main(string args[])
F. public static void main(String *args)

3. Which of these are legal array declarations or definitions? Select the two
correct answers.
A. int[] []x[];
B. int *x;

1
C. int x[5];
D. int[] x = {1,2,3};

4. Name the collection interface used to represent a sequence of numbers in a


fixed order.

5. The class Hashtable is used to implement which collection interface.


Select the one correct answer.
A. Table
B. List
C. Set
D. SortedSet
E. Map

6. What gets printed when the following program is compiled and run?
Select the one correct answer.

class test {

public static void main(String args[]) {

int i;

do {

i++;

while(i < 0);

System.out.println(i);

2
A. The program does not compile as i is not initialized.
B. The program compiles but does not run.
C. The program compiles and runs but does not print anything.
D. The program prints 0.
E. The program prints 1.

7. What gets printed when the following program is compiled and run?
Select the one correct answer.

class xyz {

static int i;

public static void main(String args[]) {

while (i < 0) {

i--;

System.out.println(i);

A. The program does not compile as i is not initialized.


B. The program compiles but does not run.
C. The program compiles and runs but does not print anything.
D. The program prints 0.
E. The program prints 1.

8. What gets printed when the following program is compiled and run?
Select the one correct answer.

3
class xyz {

public static void main(String args[]) {

int i,j,k;

for (i = 0; i < 3; i++) {

for(j=1; j < 4; j++) {

for(k=2; k<5; k++) {

if((i == j) && (j==k))

System.out.println(i);

A. 0
B. 1
C. 2
D. 3
E. 4

9. Using up to four characters what is the Java representation of the number


23 in hex?

10.What gets printed when the following program is compiled and run?
Select the one correct answer.

4
class test {

static boolean check;

public static void main(String args[]) {

int i;

if(check == true)

i=1;

else

i=2;

if(i=2) i=i+2;

else i = i + 4;

System.out.println(i);

A. 3
B. 4
C. 5
D. 6
E. The program does not compile because of the statement if(i=2)

11.Select the one correct answer. The smallest number that can be represented
using short primitive type in Java is -
A. 0
B. -127
C. -128
D. -16384
E. -32768
F. The smallest number is compiler dependent.

5
12.Given the following declarations, which of the assignments given in the
options below would compile. Select the two correct answers.

int i = 5;

boolean t = true;

float f = 2.3F;

double d = 2.3;

A. t = (boolean) i;
B. f = d;
C. d = i;
D. i = 5;
E. f = 2.8;

13.What gets printed when the following program is compiled and run. Select
the one correct answer.

public class incr {

public static void main(String args[]) {

int i , j;

i = j = 3;

int n = 2 * ++i;

int m = 2 * j++;

System.out.println(i + " " + j + " " + n + " " + m);

6
A. 4486
B. 4488
C. 4466
D. 4386
E. 4388
F. 4468

14.Given two non-negative integers a and b and a String str, what is the
number of characters in the expression str.substring(a,b) . Select the one
correct answer.
A. a + b
B. a - b
C. b - a - 1
D. b - a + 1
E. b - a
F. b

What is the result of compiling and running the following program. Select the
one correct answer.

class test {

public static void main(String args[]) {

char ch;

String test2 = "abcd";

String test = new String("abcd");

if(test.equals(test2)) {

if(test == test2)

ch = test.charAt(0);

else

ch = test.charAt(1);

7
else {

if(test == test2)

ch = test.charAt(2);

else

ch = test.charAt(3);

System.out.println(ch);

G. 'a'
H. 'b'
I. 'c'
J. 'd'

15. What is the result of compiling and running the following program.
Select the one correct answer.

class test {

public static void main(String args[]) {

int i,j=0;

for(i=10;i<0;i--) { j++; }

switch(j) {

case (0) :

j=j+1;

case(1):

j=j+2;

break;

8
case (2) :

j=j+3;

break;

case (10) :

j=j+10;

break;

default :

break;

System.out.println(j);

A. 0
B. 1
C. 2
D. 3
E. 10
F. 20

16.What is the number displayed when the following program is compiled


and run.

class test {

public static void main(String args[]) {

test test1 = new test();

System.out.println(test1.xyz(100));

9
}

public int xyz(int num) {

if(num == 1) return 1;

else return(xyz(num-1) + num);

17.Which of the following statements are true. Select the one correct answer.
A. Arrays in Java are essentially objects.
B. It is not possible to assign one array to another. Individual elements
of array can however be assigned.
C. Array elements are indexed from 1 to size of array.
D. If a method tries to access an array element beyond its range, a
compile warning is generated.

18.Which expression can be used to access the last element of an array. Select
the one correct answer.
A. array[array.length()]
B. array[array.length() - 1]
C. array[array.length]
D. array[array.length - 1]

19.What is the result of compiling and running the following program. Select
the one correct answer.

class test {

public static void main(String args[]) {

int[] arr = {1,2,3,4};

call_array(arr[0], arr);

10
System.out.println(arr[0] + "," + arr[1]);

static void call_array(int i, int arr[]) {

arr[i] = 6;

i = 5;

A. 1,2
B. 5,2
C. 1,6
D. 5,6

20.Which of the following statements are correct. Select the one correct
answer.
A. Each Java file must have exactly one package statement to specify
where the class is stored.
B. If a Java file has both import and package statement, the import
statement must come before package statement.
C. A Java file has at least one class defined.
D. If a Java file has a package statement, it must be the first statement
(except comments).

21.What happens when the following program is compiled and then the
command "java check it out" is executed. Select the one correct answer.

class check {

public static void main(String args[]) {

System.out.println(args[args.length-2]);

11
}

A. The program does not compile.


B. The program compiles but generates
ArrayIndexOutOfBoundsException exception.
C. The program prints java
D. The program prints check
E. The program prints it
F. The program prints out

22.What all gets printed when the following code is compiled and run. Select
the three correct answers.

class test {

public static void main(String args[]) {

int i[] = {0,1};

try {

i[2] = i[0] + i[1];

catch(ArrayIndexOutOfBoundsException e1) {

System.out.println("1");

catch(Exception e2) {

System.out.println("2");

finally {

System.out.println(3);

12
System.out.println("4");

A. 1
B. 2
C. 3
D. 4

23.A program needs to store the name, salary, and age of employees in years.
Which of the following data types should be used to create the Employee
class. Select the three correct answers.
A. char
B. boolean
C. Boolean
D. String
E. int
F. double

24.To make a variable defined in a class accessible only to methods defined


in the classes in same package, which of the following keyword should be
used. Select the one correct answer.
A. By using the keyword package before the variable.
B. By using the keyword private before the variable.
C. By using the keyword protected before the variable.
D. By using the keyword public before the variable.
E. The variable should not be preceded by any of the above mentioned
keywords.

25.In implementing two classes Employee and Manager, such that each
Manager is an Employee, what should be the relationship between these
classes. Select the one correct answer.

13
A. Employee should be the base class of Manager class.
B. Manager should be the base class of Employee class.
C. Manager class should include the Employee class as a data member.
D. Employee class should include Manager class as a data member.
E. The Manager and Employee should not have any relationship.

26.Select the one most appropriate answer. What is the purpose of method
parseInt defined in Integer class.
A. The method converts an integer to a String.
B. The method is used to convert String to an integer, assuming that
the String represents an integer.
C. The method is used to convert String to Integer class, assuming that
the String represents an integer.
D. The method converts the Integer object to a String.

27.What should be done to invoke the run() method on a thread for an object
derived from the Thread class. Select the one correct answer.
A. The run() method should be directly invoked on the Object.
B. The start() method should be directly invoked on the Object.
C. The init() method should be directly invoked on the Object.
D. The creation of the object using the new operator would create a
new thread and invoke its run() method.

28.What is the default priority of a newly created thread.


A. MIN_PRIORITY (which is defined as 1 in the Thread class.)
B. NORM_PRIORITY (which is defined as 5 in the Thread class.)
C. MAX_PRIORITY (which is defined as 10 in the Thread class.)
D. A thread inherits the priority of its parent thread.

14
15
Answers to Sample Test 2 

1. c, d, f
2. c. The main method must be static and return void. Hence a and b are
incorrect. It must take an array of String as argument. Hence e and f are
incorrect. As Java is case sensitive, d is incorrect.
3. a, d
4. List
5. e. The collection interface Map has two implementation HashMap and
Hashtable.
6. a. Local variables are not initialized by default. They must be initialized
before they are used.
7. d. The variable i gets initialized to zero. The while loop does not get
executed.
8. c. During various iterations of three loops, the only time i, j and k have
same values are when all of them are set to 2.
9. 0x17 or 0X17.
10.e. The statement "i=2" evaluates to 2. The expression within the if block
must evaluate to a boolean.
11.e. The range of short primitive type is -32768 to 32767.
12.c,d. Java does not allow casts between boolean values and any numeric
types. Hence a is incorrect. Assigning double to a float requires an explicit
cast. Hence b and e are incorrect.
13.a
14.e
15.b. Both Strings test and test2 contain "abcd" . They are however located at
different memory addresses. Hence test == test2 returns false, and
test.equals(test2) returns true.
16.d. The for loop does not get executed even once as the condition (i < 0)
fails in the first iteration. In the switch statement, the statement j = j +1;
gets executed, setting j to 1. As there is no break after this case, the next
statement also gets executed setting j to 3.
17.5050. The recursive function xyz essentially sums up numbers 1 to num.
This evaluates to (num * (num + 1))/2.
18.a. Java supports assignment of one array to another. Hence b is incorrect.
Array elements are indexed from 0. Hence c is incorrect. A method that
accesses array elements out of its range does not generate a compilation
error. Hence d is incorrect.
19.d. array.length gives the number of elements in the array. As indexes in
Java start from 0, d is the correct answer.

16
20.c. In the invocation of call_array, the first element is invoked using call-
by-value, and the second using call-by-reference.
21.d. import statement, package statement and class definitions are all
optional in a file. Hence a and c are incorrect. If both import and package
statements are present in a file, then package statement must appear before
the import statement. Hence b is incorrect.
22.e. The args array consists of two elements "it" and "out". args.length is set
to two.
23.a,c,d. The exception ArrayIndexOutOfBoundsException is generated as
the main method tries to access i[2]. Hence 1 gets printed. After this
finally block gets excuted, before the program exits.
24.d,e,f
25.e. A data member that does not have public/protected/private is accessible
to all methods in the same package.
26.a. The Manager and Employee share as "is a" relationship - A Manager is
an Employee. This is captured by making Employee the base class of
Manager.
27.b. The method int parseInt(Sting s) returns the integer value corresponding
to input String, assuming that the input string represents an integer in base
10.
28.b. The start() method invokes the run() method when the thread is ready to
execute.
29.d

17

You might also like