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

Core Java-Sample Questions

The document contains 40 sample questions about Java programming concepts. Some key points covered include: - Static variables that exist before object creation. - Exceptions occurring at runtime versus compilation. - Abstract classes that require subclasses to implement abstract methods. - Inner classes that can extend or implement interfaces and classes. - String and StringBuffer methods like length(), substring().

Uploaded by

Sunil Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
78 views

Core Java-Sample Questions

The document contains 40 sample questions about Java programming concepts. Some key points covered include: - Static variables that exist before object creation. - Exceptions occurring at runtime versus compilation. - Abstract classes that require subclasses to implement abstract methods. - Inner classes that can extend or implement interfaces and classes. - String and StringBuffer methods like length(), substring().

Uploaded by

Sunil Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

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

2. In java, gc() method is available in which package.


A. java.lang package
B. java.util package
C. java.awt package
D. java.io package

3. What happens in a method if an unchecked exception is thrown in a try block and there is
no matching catch block?

A. The program ignores the exception


B. The program halts immediately
C. The method throws the exception to its caller
D. This is not legal, so the program will not compile

4. Converting a primitive type data into its corresponding wrapper class object instance is
called

A. boxing
B. wrapping
C. instantiation
D. autoboxing

5. Which is true about an anonymous inner class?

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.

6. To prevent any method from overriding, we declare the method as

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. The program ignores the exception


B. The program halts immediately
C. The method throws the exception to its caller
D. This is not legal, so the program will not compile

8. The fields in an interface are implicitly specified as,

A. static only
B. protected
C. private
D. both static and final

9. When Exceptions in Java does arise in code sequence?

A. Run Time
B. Compilation Time
C. Can Occur Any Time
D. None of the mentioned

10.Which of these keywords is used to manually throw an exception?

A. try
B. finally
C. throw
D. catch

11.Which of these classes is superclass of String and StringBuffer class?

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

14.Object which can store group of other objects is called

A. Collection object
B. Java object
C. Package
D.Wrapper

15.Which of the following is not a method of the Thread Class?

A. public void run()


B. public void start()
C. public void exit()
D. public final into getPriority()

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()

17.Which of these method waits for the thread to terminate?

A. sleep()
B. isAlive()
C. join()
D. stop()

18.Which of these events is generated when a button is pressed?

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

20. Which of these methods can be used to output a sting in an applet?

A. display()
B. print()
C. drawString()
D. transient()

21. A socket provides _________________

A. a physical connection/link between sender and receiver


B. a virtual circuit through which data is transferred
C. an interface via which communicating applications can send/receive data
D. a mechanism for connecting two end systems

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.

A. Line 1, line 2 and line 3 only


B. Line 1 only
C. Line 1 and line 2 only
D. Line 2 only

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

29. What is the return type of (new ServerSocket()).accept() method ?

A. ServerSocket
B. Socket
C. DatagramSocket
D. DatagramPacket

30. Which is true about a method-local inner class?

A. It must be marked final.


B. It can be marked abstract.
C. It can be marked public.
D. It can be marked static
31. Which class does not override the equals() and hashCode() methods, inheriting them
directly from class Object?

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()

33. Which of these methods can be used to output a sting in an applet?

A. display()
B. print()
C. drawString()
D. transient()

34. Which of these Exceptions is thrown by remote method?

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()

36.Applet extends which GUI component in java?

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. (3) & (4)


B. (1) (2) & (3)
C. (1), (3) & (4)
D. All of these

38.Which is true about an anonymous inner class?

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

39.Which constructs an anonymous inner class instance?

A. Runnable r = new Runnable () { };


B. Runnable r = new Runnable (public void run () { });
C. Runnable r = new Runnable {public void run () {}};
D. System.out.println(new Runnable() {public void run() { }});

40.Which is true about a method-local inner class?

A. It must be marked final.


B. It can be marked abstract.
C. It can be marked public.
D. It can be marked static.

You might also like