SCJP Certification Questions Test # 1

Oracle Certification Program Candidate Guide

1. Which declaration of the main method below would allow a class to be started as a standalone program. Select all correct answers.

A. public static int main(char args[]);

B. public static void main(String args[]);

C. public static void MAIN(String args[]);

D. public static void main(String args);

E. public static void main(char args[]);

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

public class xyz {

public static void main(String args[]) {

for(int i = 0; i <>

for(int j = 2; j>= 0; j--) {

if(i == j) break;

System.out.println("i=" + i + " j="+j);

}

}

}

}

A. i=0 j=0

B. i=0 j=1

C. i=0 j=2

D. i=1 j=0

E. i=1 j=1

F. i=1 j=2

G. i=2 j=0

H. i=2 j=1

I. i=2 j=2

3. What gets printed when the following code is compiled and run with the following command -
java test 2
Select the one correct answer.

public class test {

public static void main(String args[]) {

Integer intObj=Integer.valueOf(args[args.length-1]);

int i = intObj.intValue();

if(args.length > 1)

System.out.println(i);

if(args.length > 0)

System.out.println(i - 1);

else

System.out.println(i - 2);

}

}

A. test

B. test -1

C. 0

D. 1

E. 2

4. In Java what expression can be used to represent number of elements in an array named arr ? array.length

5. How would the number 5 be represented in hex using up-to four characters.

6. Which of the following is a Java keyword. Select all correct answers.

A. extern

B. synchronized

C. volatile

D. friend

E. friendly

F. transient

G. this

H. then

7. Is the following statement true or false. The constructor of a class must not have a return type.

A. true

B. false

8. What is the number of bytes used by Java primitive long. Select the one correct answer.

A. The number of bytes is compiler dependent.

B. 2

C. 4

D. 8

E. 64

9. What is the result of invoking the method substring(2, 4) on the string "example"? Include the answer in quotes as the result is of type String. “ampl”

10. Which of the following is correct ? Select all correct answers.

A. The native keyword indicates that the method is implemented in another language like C/C++.

B. The only statements that can appear before an import statement in a Java file are comments.

C. The method definitions inside interfaces are public and abstract. They cannot be private or protected.

D. A class constructor may have public or protected keyword before them, nothing else.

11. What is the result of evaluating the expression 14 ^ 23. Select the one correct answer.

A. 25

B. 37

C. 6

D. 31

E. 17

F. 9

G. 24

12. Which of the following are true. Select all correct answers.

A. && operator is used for short-circuited logical AND.

B. ~ operator is the bit-wise XOR operator.

C. | operator is used to perform bitwise OR and also short-circuited logical OR.

D. The unsigned right shift operator in Java is >>.

13. Name the access modifier which when used with a method, makes it available to all the classes in the same package and to all the subclasses of the class. Protected/public

14. Which of the following is true. Select all correct answers.

A. A class that is abstract may not be instantiated.

B. The final keyword indicates that the body of a method is to be found elsewhere. The code is written in non-Java language, typically in C/C++.

C. A static variable indicates there is only one copy of that variable.

D. A method defined as private indicates that it is accessible to all other classes in the same package.

15. What all gets printed when the following program is compiled and run. Select all correct answers.

public class test {

public static void main(String args[]) {

int i, j=1;

i = (j>1)?2:1;

switch(i) {

case 0: System.out.println(0); break;

case 1: System.out.println(1);

case 2: System.out.println(2); break;

case 3: System.out.println(3); break;

}

}

}

A. 0

B. 1

C. 2

D. 3

16. What all gets printed when the following program is compiled and run. Select all correct answers.

public class test {

public static void main(String args[]) {

int i=0, j=2;

do {

i=++i;

j--;

} while(j>0);

System.out.println(i);

}

}

A. 0

B. 1

C. 2

D. The program does not compile because of statement "i=++i;"

17. What all gets printed when the following gets compiled and run. Select all correct answers.

public class test {

public static void main(String args[]) {

int i=1, j=1;

try {

i++;

j--;

if(i/j > 1)

i++;

}

catch(ArithemticException e) {

System.out.println(0);

}

catch(ArrayIndexOutOfBoundsException e) {

System.out.println(1);

}

catch(Exception e) {

System.out.println(2);

}

finally {

System.out.println(3);

}

System.out.println(4);

}

}

A. 0

B. 1

C. 2

D. 3

E. 4

18. What all gets printed when the following gets compiled and run. Select all correct answer.

public class test {

public static void main(String args[]) {

int i=1, j=1;

try {

i++;

j--;

if(i == j)

i++;

}

catch(ArithmeticException e) {

System.out.println(0);

}

catch(ArrayIndexOutOfBoundsException e) {

System.out.println(1);

}

catch(Exception e) {

System.out.println(2);

}

finally {

System.out.println(3);

}

System.out.println(4);

}

}

A. 0

B. 1

C. 2

D. 3

E. 4

19. What all gets printed when the following gets compiled and run. Select all correct answer.

public class test {

public static void main(String args[]) {

String s1 = "abc";

String s2 = "abc";

if(s1 == s2)

System.out.println(1);

else

System.out.println(2);

if(s1.equals(s2))

System.out.println(3);

else

System.out.println(4);

}

}

A. 1

B. 2

C. 3

D. 4

20. What all gets printed when the following gets compiled and run. Select all correct answer.

public class test {

public static void main(String args[]) {

String s1 = "abc";

String s2 = new String("abc");

if(s1 == s2)

System.out.println(1);

else

System.out.println(2);

if(s1.equals(s2))

System.out.println(3);

else

System.out.println(4);

}

}

A. 1

B. 2

C. 3

D. 4

21. The default layout manager for a Frame is ...

A. FlowLayout

B. BorderLayout

C. GridLayout

D. GridBagLayout

E. CardLayout

22. Which of the following are valid adapter classes in Java. Select all correct answers.

A. ComponentAdapter

B. ActionAdapter

C. AdjustmentAdapter

D. ItemAdapter

E. FocusAdapter

23. Which of the following are legal array declarations. Select all correct answers.

A. int i[5][];

B. int i[][];

C. int []i[];

D. int i[5][5];

E. int[][] a;

24. What is the range of values that can be specified for an int. Select the one correct answer.

A. The range of values is compiler dependent.

B. -231 to 231 - 1

C. -231-1 to 231

D. -215 to 215 - 1

E. -215-1 to 215

25. How can you ensure that the memory allocated by an object is freed. Select the one correct answer.

A. By invoking the free method on the object.

B. By calling system.gc() method.

C. By setting all references to the object to new values (say null).

D. Garbage collection cannot be forced. The programmer cannot force the compiler to free the memory used by an object.

26. What gets printed when the following code is compiled. Select the one correct answer.

public class test {

public static void main(String args[]) {

int i = 1;

do {

i--;

} while (i > 2);

System.out.println(i);

}

}

A. 0

B. 1

C. 2

D. -1

27. Which of these is a legal definition of a method named m assuming it throws IOException, and returns void. Also assume that the method does not take any arguments. Select all correct answers.

A. void m() throws IOException{}

B. void m() throw IOException{}

C. void m(void) throws IOException{}

D. m() throws IOException{}

E. void m() {} throws IOException

28. Which of the following are legal identifier names in Java. Select all correct answers.

A. %abcd

B. $abcd

C. 1abcd

D. package

E. _a_long_name

29. At what stage in the following method does the object initially referenced by s becomes available for garbage collection. Select the one correct answer.

void method X() {

String r = new String("abc");

String s = new String("abc");

r = r+1; //1

r = null; //2

s = s + r; //3

} //4

A. Before statement labeled 1

B. Before statement labeled 2

C. Before statement labeled 3

D. Before statement labeled 4

E. Never.

30. String s = new String("xyz");
Assuming the above declaration, which of the following statements would compile. Select all correct answers.

A. s = 2 * s;

B. int i = s[0];

C. s = s + s;

D. s = s >> 2;

E. None of the above.

31. Which of the following statements related to Garbage Collection are correct. Select all correct answers.

A. It is possible for a program to free memory at a given time.

B. Garbage Collection feature of Java ensures that the program never runs out of memory.

C. It is possible for a program to make an object available for Garbage Collection.

D. The finalize method of an object is invoked before garbage collection is performed on the object.

32. If a base class has a method defined as
void method() { }
Which of the following are legal prototypes in a derived class of this class. Select all correct answers.

A. void method() { }

B. int method() { return 0;}

C. void method(int i) { }

D. private void method() { }

33. In which all cases does an exception gets generated. Select all correct answers.
int i = 0, j = 1;

A. if((i == 0) || (j/i == 1))

B. if((i == 0) | (j/i == 1))

C. if((i != 0) && (j/i == 1))

D. if((i != 0) & (j/i == 1))

34. Which method defined in the EventObject class returns the Object that generated an event. The method should be given in the format - return_type method_name();

35. Which of the following object receives ActionEvent. Select all the correct answers.

A. List

B. Button

C. Choice

D. CheckBox

E. TextField

F. MenuItem

36. Name the class that may be used to create submenus in pull-down menus.

37. Which of the following statements are true. Select all correct answers.

A. The wait method defined in the Thread class, can be used to convert a thread from Running state to Waiting state.

B. The wait(), notify(), and notifyAll() methods must be executed in synchronized code.

C. The notify() and notifyAll() methods can be used to signal and move waiting threads to ready-to-run state.

D. The Thread class is an abstract class.

38. In which class is the wait() method defined. Select the one correct answer.

A. Applet

B. Runnable

C. Thread

D. Object

39. Which keyword when applied on a method indicates that only one thread should execute the method at a time. Select the one correct answer.

A. transient

B. volatile

C. synchronized

D. native

E. static

F. final

40. What is the name of the Collection interface used to represent elements in a sequence (in a particular order). Select the one correct answer.

A. Collection

B. Set

C. List

D. Map

41. Which of these classes implement the Collection interface SortedMap. Select all correct answers.

A. HashMap

B. Hashtable

C. TreeMap

D. HashSet

E. TreeSet

F. Vector

42. Which is the only layout manager which always honors the size of a component. Select the one correct answers.

A. FlowLayout

B. GridLayout

C. BorderLayout

D. CardLayout

E. GridBagLayout

43. Which of the following are true about interfaces. Select all correct answers.

A. Methods declared in interfaces are implicitly private.

B. Variables declared in interfaces are implicitly public, static, and final.

C. An interface can extend any number of interfaces.

D. The keyword implements indicate that an interface inherits from another.

44. Assume that class A extends class B, which extends class C. Also all the three classes implement the method test(). How can a method in a class A invoke the test() method defined in class C (without creating a new instance of class C). Select the one correct answers.

A. test();

B. super.test();

C. super.super.test();

D. ::test();

E. C.test();

F. It is not possible to invoke test() method defined in C from a method in A.

45. What is the return type of method round(double d) defined in Math class. long

46. What gets written on the screen when the following program is compiled and run. Select the one right answer.

public class test {

public static void main(String args[]) {

int i;

float f = 2.3f;

double d = 2.7;

i = ((int)Math.ceil(f)) * ((int)Math.round(d));

System.out.println(i);

}

}

A. 4

B. 5

C. 6

D. 6.1

E. 9

47. Is the following statement true or false. As the toString method is defined in the Object class, System.out.println can be used to print any object.

A. true

B. false

48. Which of these classes defined in java.io and used for file-handling are abstract. Select all correct answers.

A. InputStream

B. PrintStream

C. Reader

D. FileInputStream

E. FileWriter

49. Which of these are valid Event Listener interfaces. Select all correct answer.

A. MouseMotionListener

B. WindowListener

C. DialogListener

D. PaintListener

50. Name the collection interface used to represent collections that maintain unique elements. vector

51. What is the result of compiling and running the following program.

public class test {

public static void main(String args[]) {

String str1="abc";

String str2="def";

String str3=str1.concat(str2);

str1.concat(str2);

System.out.println(str1);

}

}

A. abc

B. def

C. abcabc

D. abcdef

E. defabc

F. abcdefdef

52. Select the one correct answer. The number of characters in an object of a class String is given by

A. The member variable called size

B. The member variable called length

C. The method size() returns the number of characters.

D. The method length() returns the number of characters.

53. Select the one correct answer. Which method defined in Integer class can be used to convert an Integer object to primitive int type.

A. valueOf

B. intValue

C. getInt

D. getInteger

54. Name the return type of method hashCode() defined in Object class, which is used to get the unique hash value of an Object.

55. Which of the following are correct. Select all correct answers.

A. An import statement, if defined, must always be the first non-comment statement of the file.

B. private members are accessible to all classes in the same package.

C. An abstract class can be declared as final.

D. Local variables cannot be declared as static.

56. Name the keyword which makes a variable belong to a class, rather than being defined for each instance of the class. Select the one correct answer.

A. static

B. final

C. abstract

D. native

E. volatile

F. transient

57. Which of these are core interfaces in the collection framework. Select all correct answers.

A. Tree

B. Stack

C. Queue

D. Array

E. LinkedList

F. Map

58. Which abstract class is the super class of all menu-related classes.

59. Which of these statements are true. Select all correct answers.

A. For each try block there must be at least one catch block defined.

B. A try block may be followed by any number of finally blocks.

C. A try block must be followed by at least one finally or catch block.

D. If both catch and finally blocks are defined, catch block must precede the finally block.


Answers

1. b

2. b, c, f

3. d

4. arr.length

5. Any of these is correct - 0x5, 0x05, 0X05, 0X5

6. b, c, f, g

7. a

8. d

9. "am"

10. a, c. b is not correct. A package statement may appear before an import statement.

11. a

12. a

13. protected

14. a, c

15. b, c

16. c

17. a, d, e

18. d, e

19. a, c

20. b, c

21. b

22. a, e

23. b, c, e

24. b

25. d

26. a

27. a

28. b, e

29. d

30. c

31. c, d

32. a, c

33. b, d

34. Object getSource();

35. a, b, e, f

36. Menu

37. b, c

38. d

39. c

40. c

41. c

42. a

43. b, c

44. f

45. long

46. e

47. a

48. a, c

49. a, b

50. Set

51. a

52. d

53. b

54. int

55. d

56. a

57. f

58. MenuComponent

59. c, d

No comments: