Core Java-Sample Questions
Core Java-Sample Questions
1. A / An ________ variable is shared by all instances of the class. It exists even before an
object is created.
A. interface
B. abstract
C. instance
D. static
3. What happens in a method if an unchecked exception is thrown in a try block and there is
no matching catch block?
4. Converting a primitive type data into its corresponding wrapper class object instance is
called
A. boxing
B. wrapping
C. instantiation
D. autoboxing
A. It can extend exactly one class and implement exactly one interface.
B. It can extend exactly one class and can implement multiple interfaces.
C. It can extend exactly one class or implement exactly one interface.
D. It can implement multiple interfaces regardless of whether it also extends a class.
A. static
B. const
C. final
D. abstract
7. What happens in a method if an unchecked exception is thrown in a try block and there is
no matching catch block?
A. static only
B. protected
C. private
D. both static and final
A. Run Time
B. Compilation Time
C. Can Occur Any Time
D. None of the mentioned
A. try
B. finally
C. throw
D. catch
A. java.util
B. java.lang
C. ArrayList
D. None of the mentioned
12.Which of these methods of class String is used to obtain length of String object?
A. get()
B. Sizeof()
C. lengthof()
D. length()
13.Which collection class allows you to grow or shrink its size and provides indexed access
to its elements, but whose methods are not synchronized?
A. java.util.HashSet
B. java.util.LinkedHashSet
C. java.util.List
D. java.util.ArrayList
A. Collection object
B. Java object
C. Package
D.Wrapper
16.Which of the methods should be implemented if any class implements the Runnable
interface?
A. start()
B. run()
C. wait()
D. notify() and notifyAll()
A. sleep()
B. isAlive()
C. join()
D. stop()
A. ActionEvent
B. KeyEvent
C.WindowEvent
D. AdjustmentEvent
19.What is an Applet?
A. An interactive website
B. A type of computer
C. A graphical user interface
D. A Java program that is run through a web browser
A. display()
B. print()
C. drawString()
D. transient()
22. When an overridden method is called from within a subclass, it will always refer to the
version of that method defined by the
A. Super class
B. Subclass
C. Compiler will choose randomly
D. Interpreter will choose randomly
23. Given a class named Book, which one of these is a valid constructor declaration for the
class?
A. Book(Book b) { }
B. Book Book() { }
C. private final Book() { }
D. void Book() { }
24. Which of these method of class StringBuffer is used to extract a substring from a String
object?
A. substring()
B. Substring()
C. SubString()
D. None of the mentioned
25.What will s2 contain after following lines of code? StringBuffer s1 = “one”; StringBuffer
s2 = s1.append(“two”);
A. one
B. two
C. onetwo
D. twoone
26. Which of the following are incorrect form of StringBuffer class constructor?
A. StringBuffer()
B. StringBuffer(int size)
C. StringBuffer(String str)
D. StringBuffer(int size , String str)
27. Which of the following statements about abstract classes in Java are true?
1. An abstract class cannot be instantiated.
2. Constructors cannot be abstract.
3. A subclass of an abstract class must defined the abstract methods.
4. Static methods may be declared abstract.
28. Which one of the following class wraps the byte stream to character stream
A. InputStreamReader
B. FileInputStream
C. FileOutputStream
D. None of the above
A. ServerSocket
B. Socket
C. DatagramSocket
D. DatagramPacket
A. java.lang.String
B. java.lang.Double
C. java.lang.StringBuffer
D. java.lang.Character
32. Which of these methods can be used to obtain the command name for invoking
ActionEvent object?
A. getCommand()
B. getActionCommand()
C. getActionEvent()
D. getActionEventCommand()
A. display()
B. print()
C. drawString()
D. transient()
A. RemoteException
B. InputOutputException
C. RemoteAccessException
D. RemoteInputOutputException
35. Which of these is a method to clear all the data present in output buffers?
A. clear()
B. flush()
C. flush()
D. close()
A. Panel
B. Frame
C. Frame
D. Janel
37. Which of the following keywords are used to control access to a class member?
(1) Public
(2) Private
(3) Protected
(4) Interface
A. It can extend exactly one class and implement exactly one interface.
B. It can extend exactly one class and can implement multiple interfaces.
C. It can extend exactly one class or implement exactly one interface.
D. It can implement multiple interfaces regardless of whether it also extends a Class