Java MCQ
Java MCQ
DEPT-COMPUTER SCIENCE
SUB-JAVA
PREPARED BY-Assistant prof. TAPASI DAS
1.The Java interpreter is used for the execution of the source code.
True
False
Ans: a.
The Java Compiler is used for compilation and the Java Interpreter
is used for execution of the application.
7) What are the three OOPs principles and define them?
Encapsulation:
Inheritance:
Is a feature that allows one interface to be used for a general class of actions.
8) What is a
compilation unit?
Ans : Java source
code file.
9) What output is displayed as the result of executing
the following statement? System.out.println("// Looks
like a comment.");
// Looks like a comment
No output is
displayed
Ans : a.
10) In order for a source code file, containing the public class
Test, to successfully compile, which of the following must be true?
It must have a package
statement It must be
named Test.java
It must import java.lang
a)True b)FlseAns: a.
12)An array of arrays can be created.
a)True b)False
Ans: a.
13) What is a string?
a)True b)False
String
integer
Float
Ans : a.
Ans : c.
26)Can a double value be
cast to a byte?
a)yes
b)no
Ans : Yes
27)Can a byte object be cast to a double value ?
a)yes
b)no
Ans : No. An object cannot be cast to a primitive value.
28) What are order of precedence and associativity?
Ans : Order of precedence the order in which operators are evaluated in
expressions.
Associativity determines whether an expression is evaluated left-right or right-
left.
Ans: a.
38)Boolean values can be cast into any
other primitive type.
a)True b)False Ans: b.
Ans: b,d.
41)What is an example of polymorphism?
Inner class
Anonymous classes
Method overloading
Method overriding
Ans : c
Exception Handling
49)The finally block is executed when an exception is thrown,
even if no catch matches it. True/False
Ans : True
50)The subclass exception should precede the base class exception when
used within the catch clause. True/False
Ans : True
51)The statements following the throw keyword in a
program are not executed. True/False
Ans : True
MULTI THREADING
53)What are the two types of
multitasking?
Ans : 1.process-based
2.Thread-based
5.stop()
6.start()
7.sleep()
8.destroy()
59)What are all the methods used for Inter Thread communication and
what is the class in which these methods are defined?
Ans :1. wait(),notify() & notifyall()
2. Object class
Ans : True
70)Garbage collector thread belongs to
which priority? Ans : low-priority
Inheritance
Ans : A super class is a class that is inherited whereas subclass is a class that
does the inheriting.
Ans: It must provide all of the methods in the interface and identify
STRING HANDLING
String s1 = "abc";
String s2 = "def";
String s3 = s1.concat(s2.toUpperCase( ) );
System.out.println(s1+s2+s3);
}
}
a)abcdefabcdef
b)abcabcDEFDEF
c)abcdefabcDEF
d)None of the above
ANS : c.
81)Which of the following methods are methods of the String class?
a)delete( )
b)append( )
c)reverse( )
d)replace( )
Ans : d.
b)s.toUpperCase( )
c)s.replace( )
d)s.valueOf( )
Ans : a and b.
Ans : Applet is a dynamic and interactive program that runs inside a Web page
displayed by a Java capable browser. We don’t have the concept of
Constructors in Applets.
Ans : Ask the applet for its applet context and invoke showDocument() on that
context object.
Eg. URL targetURL;
String URLString
AppletContext context = getAppletContext();
try{
} catch (Malformed
URLException e){ // Code
for recover from the
exception
}
context. showDocument (targetURL);
87)Can applets on different pages communicate with each other?
Ans : Ask the applet for its applet context and invoke showDocument() on that
context object.
Eg. URL targetURL;
String URLString
AppletContext context = getAppletContext();
try{
} catch (Malformed
URLException e){ // Code
for recover from the
exception
}
context. showDocument (targetURL);
90)Can applets on different pages communicate with each other?
False.
Ans : a.
94)All Applets must import java.applet and java.awt.
True.
False.
Ans : a.
EVENT HANDLING
a.Buttons
b.Labels
c.Check boxes
Ans : a.
96) Which of the following are true?
a.The MouseListener interface defines methods for handling mouse clicks.
b.The MouseMotionListener interface defines methods for handling mouse
clicks.
c.The MouseClickListener interface defines methods for handling mouse clicks.
d.The ActionListener interface defines methods for handling the clicking of a
button.
Ans : a and d.
a.t.addTextListener(eh);
b.eh.addTextListener(t);
c.addTextListener(eh.t);
d.addTextListener(t,eh);
Ans : a.
98)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 processEvent( ) methods.
100) Which of the following is the highest class in the event-delegation model?
a.java.util.EventListener
b.java.util.EventObject
c.d.java.awt.AWTEvent
d.java.awt.event.AWTEvent
Ans : b