Tuesday, August 13, 2013

Java MCQ Test – 4


Que.1. Which cannot directly cause a thread to stop executing?

A:        Calling a yield method.
B:        Calling the start method on another Thread object.
C:        Calling the notify method on an object.
D:        Calling wait method on an object.

Right Answer: C

Que.2. Which of the following statement is true?

A:        An anonymous inner class can access final variables in any
B:        enclosing scope.
C:        An anonymous inner class may be declared as protected.
D:        An anonymous inner class can implement multiple interface.

Right Answer: B

Que.3. Which statement is true for the Class java.util.HashSet?

A:        The collection is guaranteed to be immutable.
B:        The elements in the collection are unique.
C:        The elements in the collection are ordered.
D:        The elements in the collection are synchronized.

Right Answer: B

Que.4. Which of the following is false for vector class?

A:        The size of a Vector is static
B:        The Vector class implements an incremental array of objects.
C:        The vector components can be accessed using an integer index.
D:        The size of a Vector increases or decreases as needed to accommodate the items.

Right Answer: A
Que.5.

class Test
{
public static void main(String [] args)
{
Integer i = new Integer(0);
add(i);
System.out.println(i);
}
static void add(Integer i)
{
int val = i.intValue();
val+=3;
i = new Integer(val);
}
}

What would be the output?

A:        Compile Error
B:        0
C:        3
D:        Runtme Exception

Right Answer: B

Que.6. Java Constructor

class Add
{
int add (int x , int y)
{
return (x+y);
}
}
class FloatAdd extends Add
{
float add(float x, float y)
{
return (x+y);
}
}
class Test
{
public static void main(String [] args)
{
Add a = new Add();
FloatAdd addObj = (FloatAdd) a;
System.out.println("Result : "+addObj.add(10, 20));
}
}

What would be output?

A:        30.00
B:        30
C:        Complie error
D:        Runtime Exception

Right Answer: C

Que.7. What is the purpose of code attribute of applet tags?

A:        A URL that points to the class of the applet
B:        A URL to the applet when it is stored in a Java Archive or ZIP file
C:        Indicates the base URL of the applet if the code attribute is relative
D:        Defines the horizontal spacing around the applet

Right Answer: A

Que.8. ______________ is a command that disassembles a class file

A:        javaamd
B:        javacmd
C:        javad
D:        javap

Right Answer: D

Que.9.

String a = "Hello World";
String b = "Hello World";
System.out.println(a.equals(b));
System.out.print(a==b);
System.out.print(a == b.intern());

What would be output?

A:        Compile time error
B:        True false false
C:        true false true
D:        true true true

Right Answer: D

Que.10.

public class Test
{
public static void main(String [] args)throws Exception
{
Object object = new Object();
synchronized (Thread.currentThread())
{
object.wait();
object.notify();
}
}
}

What is the result?

A:        Compiles successfully.
B:        Throws an InterruptedException.
C:        Throws an IlleagalStateException.
D:        Throws an IllegalMonitorStateException

Right Answer: D

Que.11.
To execute the threads one after another

A:        the keyword synchronize is used
B:        the keyword synchronizable is used
C:        the keyword synchronized is used
D:        None of the above

Right Answer: B

Que.12. BY restricting the state change of a class object, I can make a class immutable?

A:        No
B:        Yes

Right Answer: B

Que.13. DataInputStream is an example of

A:        Output stream
B:        I/O stream
C:        Filtered stream
D:        File stream

Right Answer: C

Que.14. Java Constructor

class Nest
{
Nest()
{
System.out.print("Nest");
}
Nest (long l)
{
this();
System.out.print(l);
}
Nest(int i)
{
this(i);
System.out.print(i*2);
}
}
Public static voidmain(String[] args)
{
int i = 4;
new Nest(i);
}

What would be the output?

A:        Nest48
B:        Nest84
C:        Nest44
D:        Compile Error

Right Answer: D

Que.15. Which of the following below are abilities of Reflection API in Java?

A:        Determining state of an object
B:        Both B and C
C:        Determining duplicate classes
D:        Determination of the class of an object

Right Answer: D

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

Right Answer: B

Que.17. What is the difference between java beans and EJB?

A:        Java beans are reusable components that can be used for customized user objects while EJB are reusable components that are developed to comply with enterprise specification adhering to setter and getter methods and two public constructors.
B:        Java beans are reusable components that can be used for customized user objects while EJB are reusable components that are developed to comply with enterprise specification adhering to setter and getter methods and one public constructor.
C:        Java beans are reusable components that can be used for customized user objects while EJB are reusable components that are developed to comply with enterprise specification adhering to setter and getter methods and many public constructors.
D:        Java beans are reusable components that can be used for customized user objects while EJB are reusable components that are developed to comply with enterprise specification adhering to setter and getter methods with no public constructor.

Right Answer: B

Que.18. A thread which has invoked wait() method of an object, still owns the lock of the object. Is this statement true or false?

A:        True
B:        False

Right Answer: B

Que.19. The object of DataInputStream is used to

A:        To covert binary stream into character stream
B:        To covert character stream into binary stream
C:        To write data onto output object
D:        All of the above

Right Answer: A

Que.20. 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 int getPriority()

Right Answer: C

No comments:

Post a Comment