MCQ on Core Java with Answers set-1

468x60

1. Which exception is thrown by the read( ) method of input stream class?

A) Exception

B) ClassNotFoundException

C) read Exception

D) IOException



2. What garbage collection in the context of java?

A) The operating system periodically deletes all of the java files available on the system.

B) Any package imported in a program and not used in automatically deleted.

C) When all references to an object are gone, the memory used by the object is automatically reclaimed.

D) The JVM checks the output of any Java program and deletes anything that doesn't make sense.



3. In order for a source code file, containing the public class test, to successfully compile, which of the following must be true?

A) It must have a package statement

B) It must be named test.java

C) It must import java.lang

D) It must declare a public class named test.



4. Which of the following are true about the Error and Exception classes?

A) Both classes extend throwable

B) The error class is final and exception class is not.

C) The Exception class is final and the Error is not.

D) Both classes implement Throwable



5. Which of the following are true?

A) The void class extends the class class

B) The float class extends double class

C) The system class extends the runtime class

D) The integer class extends the number class



6. How do you create a Reader object from an InputStream object?

A) Use the static createReader() method of InputStream class

B) Use the static createReader() method of Reader class

C) Create an InputStreamReader object passing the InputStream object an an argument to the InputStreamReader constructor.

D) Create an OutputStreamReader object, passing the InputStream object as an argument to the OutputStreamReader constructor.



7. Which of the following is true?

A) The event inheritance model has replaced the event delegation model

B) The event inheritance model is more efficient than event delegation model

C) The event delegation model uses event listeners to define the methods of event handling classes.

D) The event delegation model uses the handleEvent() method to support event handling.



8. Which of the following is the highest class in the event delegation model?

A) java.util.EventListner

B) java.util.EventObject

C) java.util.AWTEvent

D) java.util.event.AWTEvent



9. When two or more objects are added as listeners for the same event, which listener is first invoked to handle the event?

A) The first object that was added as listner.

B) The last object that was added as listner

C) There is no way to determine which listener will be invoked first.

D) It is impossible to have more than one listener for a given event.



10. Suppose that you want to have an object eh handle the TextEvent of TextArea object t. How should you add eh as the event handler for?

A) t.addTextListener(eh);

B) eh.addTextListner(t);

C) addTextListner(eh.t);

D) addTextListner(t,eh);



11. What is the preferred way to handle an object's events in Java 2?

A) Override the object's handleEvent( ) method.

B) Add one or more event listeners to handle the events

C) Have the object override its process Event( ) methods.

D) Have the object override its dispatch Event( ) methods.



12. Which component method is used to access a component's immediate container?

A) getVisible()

B) getImmediate()

C) getParent()

D) getContainer()



13. Which of the following creates a List with 5 visible items and multiple selection enabled?

A) new List(5, true)

B) new List(true, 5)

C) new List(5, false)

D) new List(false, 5)



14. An Applet has its Layout Manager set to the default of FlowLayout. What code would be the correct to change to another Layout Manager?

A) setLayoutManager(new GridLayout());

B) setLayout(new GridLayout(2,2));

C) setGridLayout(2,2);

D) setBorderLayout();



15. How do you change the current layout manager for a container?

A) Use the setLayout method.

B) Once created you cannot change the current layout manager of a component

C) Use the setLayoutManager method.

D) Use the updateLayout method.



16. Which of the following methods can be used to draw the outline of a square within a JAVA.awt.Component object?

A) drawLine()

B) fillRect()

C) drawPolygon()

D) drawPolygon()



17. State true or false

i) JPanel is a class included in awt package

ii) Anonymous classes are mostly used for event handling

iii) Names of anonymous classes must be unique

iv) JOptionPane is an inner class

A) i-false, ii-false, iii-true, iv-true

B) i-true, ii-false, iii-true, iv-false

C) i-false, ii-true, iii-false, iv-false

D) i-true, ii-true, iii-false, iv-true



18. State true or false

i) Java RMI supports distributed objects written entirely in java

ii) Java RMI makes use of stubs and skeleton

iii) In Java RMI an object registers itself with a media server

iv) IDL is interface declaration language

A) True, True, False, False

B) False, True, True, True

C) True, False, True, False

D) True, True, True, True



19. Match the following

a) Datagram Socket        i) UDP connection

b) URL                           ii) provides necessary framework of debugging java programs

c) java.net                      iii) makes it possible to communicate over a network with java programs

d) sun.tools.debug          iv) is a java object that represent WWW address

A) a-i, b-iv, c-iii, d-ii

B) a-i, b-iv, c-ii, d-iii

C) a-ii, b-iii, c-i, d-iv

D) a-ii, b-i, c-iii, d-iv



20. State true or false

i) public can only be assigned to class

ii) protected protects a statement

iii) protected method is never accessible outside the package

iv) friendly variable may be accessible outside class

A) True, True, False, True

B) False, False, False, True

C) False, True, False, False

D) True, False, False, False


View Answers:


1. D) IOException
2. C) When all references to an object are gone, the memory used by the object is automatically reclaimed
3. B) It must be named test.java
4. A) Both classes extend throwable
5. D) The integer class extends the number class
6. C) Create an InputStreamReader object passing the InputStream object an an argument to the InputStreamReader constructor.
7. C) The event delegation model uses event listeners to define the methods of event handling classes.
8. B) java.util.EventObject
9. C) There is no way to determine which listener will be invoked first.
10. D) addTextListner(t,eh);
11. B) Add one or more event listeners to handle the events
12. C) getParent()
13. A) new List(5, true)
14. B) setLayout(new GridLayout(2,2));
15. A) Use the setLayout method
16. A) drawLine()
17. C) i-false, ii-true, iii-false, iv-false
18. A) True, True, False, False
19. A) a-i, b-iv, c-iii, d-ii
20. A) True, True, False, True




Related Posts:



468x60
معلومات عن التدوينة الكاتب : Unknown بتاريخ : الخميس، 28 أغسطس 2014
المشاهدات :
عدد التعليقات: 0، للإبلاغ عن رابط معطوب اضغط هنا
250x300

شكرا لتعليقك
المتميز