OCPJP 6 Mock Exam – 6

1 . Please select signed integrals

  1. char, byte, and short
  2. byte, short, int, and long
  3. char, short, and long

2 . Java characters are …

  1. ASCII code
  2. Binary code
  3. Unicode
  4. ANSI code

3 . Please select the size of an int type

  1. 32 bytes
  2. 16 bits
  3. 32 bits
  4. 16 bytes

4 . Select default value of boolean type

  1. true
  2. false
  3. 0
  4. 1

5 . Consider the following line of code:

<br />char x[]=new char[10];<br />

After execution, what is value of x[0]?

  1. 0
  2. ‘\u0000′
  3. null

6 . A package statement MUST exist in all classes

  1. True
  2. False

7 . Please choose invalid identifiers

  1. temp
  2. BIGint
  3. 25_length
  4. !length

8 . Please select floating point types

  1. byte
  2. int
  3. double
  4. short
  5. long
  6. float

9 . All operands are evaluated left to right

  1. true
  2. false

10 . Consider the following line of code:

<br />byte x=64;<br />byte y=5;<br />byte z= (byte)(x*y);<br />

After execution what is value of z?

  1. 320
  2. 0
  3. 645
  4. 64

11 . Consider the following line of code:

<br />int x=7;<br />int y=4;<br />int z=7/4;<br />

After execution what is value of z?

  1. 1.75
  2. 0
  3. 1
  4. 2

12 . Please select the true statement for ! operator

  1. The ! operator inverts the value of a boolean expression
  2. The ! operator inverts the bit pattern of an integral expression.
  3. Both A and B
  4. None of the above

13 . Please select arithmetic operations which can result in AirthmeticException

  1. Multiplication: *
  2. Division: /
  3. Modulo: %
  4. Addition: +
  5. Subtraction: -

14 . Please select operators which perform bit shifts of the binary representation of the integral types

  1. <<
  2. >>
  3. >>>
  4. ~
  5. &
  6. ^
  7. |

15 . A protected method may be overridden by …

  1. A private method
  2. A protected method
  3. A public method
  4. All of the above

16 . A public method may not be overridden by …

  1. A private method
  2. A protected method
  3. A public method
  4. All of the above

17 . The private modifier can be applied to …

  1. A variable
  2. A method
  3. A top level class
  4. All of the above

18 . The abstract modifier can NOT be applied to …

  1. A variable
  2. A method
  3. A class
  4. A constructor

19 . A class variable is declared using following modifiers

  1. protected
  2. private
  3. public
  4. static

20 . An unary operator operates on a single value

  1. True
  2. False

21 . The following types of loop are guaranteed to be executed at least once

  1. The do loop
  2. The while loop
  3. The for loop
  4. All of the above

22 . The switch() construct is used to make a choice based upon …

  1. A char value
  2. An int value
  3. A String value
  4. None of the above

23 . The circumstances that can prevent execution of the code in a finally block are

  1. The death of the thread
  2. The use of System.exit()
  3. It is always guaranteed to be executed.

24 . Select correct statement(s)

  1. The continue statement abandons the loop altogether
  2. The break statement causes the current iteration of the loop to be abandoned.
  3. The break statement abandons the loop altogether

25 . How can you declare a overloaded method?

  1. Reusing the method name with different arguments and same return type
  2. Reusing the method name with different arguments and different return type
  3. Reusing the name with identical arguments and return type
  4. None of the above

26 . How can you declare a overriding method?

  1. Using the same method name with identical arguments and return type
  2. Using the same method name with identical arguments and different return type
  3. Using the same method name with different arguments and same return type
  4. All of the above

27 . When a default constructor is provided by the compiler?

  1. If you define no constructor at all in a class
  2. When you define at least one constructor
  3. It is always provided whether you define a constructor or not
  4. It is never provided

28 . A static inner class can access …

  1. instance variables of the enclosing class
  2. static variables of the enclosing class
  3. Both A and B
  4. None of the above

29 . An inner class created inside a method can access

  1. Any local variables of a method that contain an inner class.
  2. Any instance variables of the enclosing class
  3. Any final variables of the enclosing class or a method that contain an inner class.
  4. None of the above

30 . Please select true statement(s) for an anonymous inner class

  1. An anonymous class can not extend to a superclass
  2. An anonymous class can not implement an interface
  3. An anonymous class can extend to a supperclass and implement an interface both.
  4. An anonymous class can extend to a supperclass or implement an interface

31 . Please select true statement(s) for a member inner class

  1. An inner class in class scope can have any accessibility of the top level class, including private.
  2. An Inner class defined local to a block may be static
  3. An anonymous inner class can not declare a constructor.
  4. An inner class can not have same name as enclosing class.
  5. All of the above

32 . Please select invalid statement(s) for a thread

  1. You can restart a dead thread
  2. You can’t call the methods of a dead thread
  3. Both of the above
  4. None of the above

33 . Select correct statements for a java.lang.String

  1. Strings are sequences of 16 bit Unicode characters.
  2. Strings are immutable.
  3. Both of the above
  4. None of the above

34 . Select correct statements for == operator.

  1. It compare object reference of two objects
  2. It compare the value of two objects
  3. Both of the above
  4. None of the above

35 . Please select collection(s) that do not reject duplicates

  1. java.util.List
  2. java.util.Set
  3. java.util.Map
  4. All of the above

36 . Please select a default layout manager of the java.awt.Panel

  1. java.awt.FlowLayout with left justified
  2. java.awt.FlowLayout with center justified
  3. java.awt.FlowLayout with right justified
  4. None of the above

37 . Please select a default layout manager for the java.awt.Frame

  1. java.awt.FlowLayout
  2. java.awt.BorderLayout
  3. java.awt.GridBagLayout
  4. None of the above

38 . Please select true statement for prefix operator(++x/–x).

  1. The prefix operator(++x/–x) evaluates the value of the operand after increment/decrement operation.
  2. The prefix operator(++x/–x) evaluates the value of the operand before increment/decrement operation.
  3. Both A and B
  4. None of the above

39 . Please select true statement(s) for shift operators.

  1. >>> operator always produces a positive number.
  2. >> always produces a positive number for a positive number.
  3. >> always produces a negative number for a negative number.
  4. None of the above

40 . Please select true statement(s) for shift operators.

  1. Shifting is not allowed in long integral type
  2. Shifting is not allowed in float integral type
  3. Shifting is not allowed in double integral type
  4. Shifting is not allowed in int integral type.

41 . Please identify correct assignment for boolean type.

  1. boolean javaExam=true;
  2. boolean javaExam=True;
  3. boolean javaExam=1;
  4. All of the above

42 . Bitwise operator can be applied to …

  1. Integral types
  2. Float types
  3. Both of the above
  4. None of the above

43 . instanceof operator can be used with …

  1. interfaces
  2. Arrays
  3. Classes
  4. All of the above

44 . Please select true statement(s)

  1. The equals method compares content of two objects
  2. The == operator tests reference of two objects
  3. The equals method compares reference of two objects.
  4. The == operator compares content of two objects

45 . Please identify invalid use of comparison operator for the following code:

<br />String s=new String("S");<br />String t=new String("T");<br />int x=83;<br />int y=84;<br />

Choose the one below:

  1. s == t
  2. x!=y
  3. x==s
  4. s!=t

46 . Please select true statement(s) for instanceof operator:

  1. The instanceof operator can be applied to object reference
  2. The instanceof operator can be applied to an array.
  3. Both of the above
  4. None of the above

47 . please select true statement(s) for static modifier.

  1. A static method can access non-static variables of the class.
  2. A static method can call non-static methods.
  3. A static method can be overridden by non-static method.
  4. None of the above

48 . Please, select true statement(s) for thread.

  1. Invoking a constructor of a Thread registers the thread with thread scheduler.
  2. Calling a start() method of thread registers the thread with thread scheduler.
  3. Calling a run() method of thread registers the thread with thread scheduler.
  4. All of the above.

49 . Invoking yield() on a running thread cause following effect(s):

  1. A running thread will be placed in suspended state.
  2. A running thread will be placed in sleeping state.
  3. A running thread will be placed in ready state.
  4. Neither of the above.

50 . The default priority of the thread is

  1. 0
  2. 1
  3. 5
  4. 10

51 . Which of the following methods are NOT static of Thread class?

  1. start()
  2. sleep(long l)
  3. run()
  4. yield()

52 . Select true statement(s) about an inner class declared inside a method, also known as local inner class

  1. The local inner class can access any local variables declared in the method and the parameters passed to the method.
  2. The local inner class can access only public variables declared in enclosing class
  3. The local inner class can access public, private, and protected variables declared in enclosing class.
  4. The local inner class can access only final declared variables in the method.

53 . How can you prevent class JavaExam from being extended?

  1. declare class static JavaExam
  2. declare class synchronized JavaExam
  3. declare class final JavaExam
  4. None of the above

54 . Assume that following methods are declared in one class.
1. public void addElement(Object javaExam)
2. public void addElement( Object [] javaExam)
3. public Object addElement ( int index, Object javaExam)
Please select true statement(s) for above methods.

  1. All methods are example of overloading method
  2. All methods are example of overriding method
  3. Method # 1 and method # 2 are example of overloading method, whereas method # 3 is an example of overriding method.
  4. None of the above

55 . When can’t you override a method?

  1. when method is declared abstract
  2. When method is declared final
  3. when method is declared private
  4. when method is declared static

56 . Please select invalid declaration of the top level class

  1. public abstract final class JavaExam
  2. public final class JavaExam implement Runnable
  3. protected static class JavaExam
  4. public class JavaExam extend Thread

57 . Please select invalid types for a switch construct

  1. float
  2. long
  3. String
  4. All of the above

58 . Please select invalid java keywords

  1. include
  2. ifdef
  3. sizeof
  4. goto

59 . Which of the following statements are NOT true about Java garbage collection Thread?

  1. The garbage collection thread has a low priority
  2. The garbage collection thread can be invoked at any time
  3. A call to System.gc() is guaranteed to invoke garbage collection thread immediately
  4. A call to Runtime.getRuntime().gc() is guaranteed to invoke garbage collection thread immediately

60 . An inner class can not declare______ variables.

  1. static
  2. protected
  3. final
  4. transient

61 . Which of the following types can be added to java.util.Vector?

  1. reference
  2. null
  3. int
  4. All of the above

62 . Please select a true statement about delete() method of java.io.File.

  1. It can delete a file
  2. It can delete an empty directory
  3. Both of the above
  4. Neither of the above

63 . The continue statement causes the current iteration of the loop to be skipped and the next iteration starts.

  1. True
  2. False

64 . The return type of constructor is void.

  1. True
  2. False

65 . ‘null’ is valid java type.

  1. True
  2. False

66 . Invoking a constructor of java.io.File class creates a file on the file system.

  1. True
  2. False

67 . Select true statement(s) about native modifier.

  1. native modifier can be applied to a class
  2. native modifier can be applied to a method
  3. native modifier can be applied to an instance variable
  4. native variable can be applied to a class variable

68 . What method(s) needed to be declared by a class implementing Runnable interface?

  1. public void start()
  2. public void run()
  3. public boolean start()
  4. public boolean run()

69 . The priority of a newly created thread is always Thread.NORM_PRIORITY.

  1. True
  2. False

70 . What methods are declared in java.lang.Thread class?

  1. public static void sleep(long millis, int nanos)
  2. public static native void sleep(long millis, int nanos)
  3. public static native void sleep(long millis)
  4. public static void sleep(long millis)

71 . A yield method of the Thread class suspends the operation of the current thread.

  1. True
  2. False

72 . What methods are NOT synchronized in java.util.Vector class?

  1. size()
  2. add(int index, Object element)
  3. capacity()
  4. get(int index)

73 . Please select unchecked exception(s)?

  1. java.lang.NullPointerException
  2. java.lang.ClassNotFoundException
  3. java.lang.ClassCastException
  4. java.awt.AWTException

74 . Which of the following declarations are valid to throw an exception?

  1. throw new java.lang.Exception();
  2. throws new java.lang.Exception();
  3. Both of the above
  4. None of the above

75 . Which of the following classes are immutable?

  1. java.lang.String
  2. java.lang.StringBuffer
  3. java.util.Vector
  4. java.lang.Integer

76 . Which of the following classes store and retrieve values based on a key?

  1. java.util.Hashtable
  2. java.util.Vector
  3. java.util.LinkedList
  4. java.util.HashMap

77 . Which of the following classes can store null value for a key?

  1. java.util.Hashtable
  2. java.util.HashMap
  3. java.util.Properties
  4. All of the above

78 . java.util.Vector uses synchronized methods to store and retrieve values.

  1. True
  2. False

79 . java.util.Hashtable uses synchronized methods to store and retrieve values.

  1. True
  2. False

80 . java.util.HashMap uses synchronized methods to store and retrieve values.

  1. True
  2. False

81 . Which of the following collections maintain object references in the order they were added?

  1. java.util.Vector
  2. java.util.Hashtable
  3. java.util.HashMap
  4. java.util.ArrayList

82 . java.util.hashtable implements which of the following interfaces?

  1. java.util.Dictionary
  2. java.util.Map
  3. java.util.HashMap
  4. java.util.Hashmap

Answers

1 : 2 is correct.

2 : 3 is correct.

3 : 3 is correct.

4 : 2 is correct.

5 : 2 is correct.

6 : 2 is correct.

7 : 3 & 4 is correct.

8 : 3 & 6 is correct.

9 : 1 is correct.

10 : 4 is correct. A byte value can represent a range of -128 to +127. Arithmetically answer is 320, but when you store this result to a byte variable you will get a value 64 since result is out of the range (-128 to +127).

11 : 3 is correct.

12 : 1 is correct.

13 : 2 & 3 is correct.

14 : 1,2 & 3 is correct.

15 : 2 & 3 is correct.

16 : 1 & 2 is correct.

17 : 1 & 2 is correct.

18 : 1 & 4 is correct.

19 : 4 is correct.

20 : 1 is correct. + and – operator can take two values.

21 : 1 is correct.

22 : 1 & 2 is correct.

23 : 1 & 2 is correct.

24 : 3 is correct.

25 : 1 & 2 is correct.

26 : 1 is correct.

27 : 1 is correct.

28 : 2 is correct.

29 : 3 is correct.

30 : 4 is correct.

31 : 1,3 & 4 is correct.

32 : 3 is correct.

33 : 3 is correct.

34 : 1 is correct.

35 : 1 is correct.

36 : 2 is correct.

37 : 2 is correct.

38 : 1 is correct.

39 : 2 & 3 is correct.

40 : 2 & 3 is correct.

41 : 1 is correct.

42 : 1 is correct.

43 : 4 is correct.

44 : 1 & 2 is correct.

45 : 3 is correct.

46 : 3 is correct.

47 : 4 is correct.

48 : 2 is correct.

49 : 3 is correct.

50 : 3 is correct.

51 : 1 & 3 is correct.

52 : 3 & 4 is correct.

53 : 3 is correct.

54 : 1 is correct.

55 : 2 is correct.

56 : 1,2,3 & 4 is correct.

57 : 4 is correct.

58 : 1,2 & 3 is correct.

59 : 2,3 & 4 is correct.

60 : 1 is correct.

61 : 1 & 2 is correct.

62 : 3 is correct.

63 : 1 is correct.

64 : 2 is correct.

65 : 1 is correct.

66 : 2 is correct.

67 : 2 is correct.

68 : 2 is correct.

69 : 2 is correct. A newly created thread inherits the priority of the Thread that creates it.

70 : 1 & 3 is correct.

71 : 1 is correct.

72 : 1,2 & 3 is correct.

73 : 1 & 3 is correct.

74 : 1 is correct.

75 : 1 & 4 is correct.

76 : 1 & 4 is correct.

77 : 2 is correct.

78 : 1 is correct.

79 : 1 is correct.

80 : 2 is correct.

81 : 1 & 4 is correct.

82 : 2 is correct.

Comments

comments

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Speak Your Mind

*