Java MCQ
Java MCQ
Group-A
(Multiple Choice Type Questions)
Choose the corect altematives for the following
aWhat s the resut of atempting to compile and run the program>
ciass Test (
ublic
public static void main (String [l args)
int x 0, y 0:
x 5 Y+*
Systen.out.print (x * +y);
x 0:
Y 0;
5 ++Y
System. out .print (x *
+y)
//end of main
end of test class
int i
public Test ()
System.out.println("Hello *" i = *+i) ;}
String s2 = A . S2";
Class B extends A{
String sl = *B.s1";
POPULAR PUBLICATIONS
i ar9s) (
a) ine 1
b) line 2
c) line 3
MCA JAVA-142 d) line 3 and line 4
OBJECT ORIENTED PROGRAMMING WITHIAVA
What
will be
the tput
i) class Test (
public
u b l i o
static vold maln (String [1 args) (
system.out.print ("1") ;
tryl
return
] catch (Exception e) (
System.Out.print (*2")
finally{
System.out.print ("3") ;
System.out.print ("4" )
/ / e n d o f main
end o t
test class
//
a) 1234 b) 14 c) 134 d) 13
class B(
private string name;
public B(String s){
name S;
class E
public static void m()
B x1 = new B("X");
B yl = new B("y"):
E.m();
System.gc()
}//end of main
//end of test
class
a) YX b) prints YYXX c) prints nothing d) none of th 2se
MCA JAVA-143
POFULAR PUBLICATIONS
(
Whet wil be output ()
args)
void
ic
pub
Cstat
String$ Buffer ()
Tnteger x r
new
String
sb
S t r i n g Buf
fer
if Ix15)
s.concat ( "Hi°);
sb);
(s
System.cut.print
end of nain
MCA JAVA-144
POPULAR PUBLICATIONS
in JAVA7
a h a t are ithe usesexcepton handling "Entry of negative age.of
that handles an exception a person
b W t e a program using java first 30 n a t .
the square
roois
of the
Wte a Mutithreading
Runnable unterface
program to generale
do we
need it7
umbera
Why
by Synchronzation ?
Type Question No. 3.
C ) W h t do you mean
UANDLING,Short Answer
See Topic:
ENCEPTON
Ser Togpic:
APPLET, Long Answer Type Short Answer Type Question No,I1
POLYMORPHISM,
AND
Question No. 7.
INHERITANCE
Topic:
bi See
AND OBJECTS, Long
Answer Type
cr Topic:
CLASSES
Type Question No. 8.
AND OBJECTS,
Long Answer
CLASSES
d See Topic:
QUESTION 2015
Group-A
) inti=2; + i + 2)
S y s t e m . o u t . p r i n t l n ( "welcome"
The output is c ) compiler error d) none of these
b) welcome 22
a) weicome 4
Cring
ystem.out.println (a)
The output is c ) compiler error d) runtime exception
b) a
a) 3
MCA JAVA-146
OBIECT ORIENTED FROKGRAMMING WITHJAYA
nt
fer a
systemut print in lai
The o u t
2
nt
y s t em. out print in (i
The output s
)4 c) 3 d) compiler error
a7T(317:
a) 3 b) 7
c) compiler error d) runtime exception
vString s INDIA";
a) D b) 2 c) N d) exception occurs
MCA JAVA-147
POPULAR PUGLICATIONS
gUESTION 2016
GROUP-A
what will happen when you compile and run the programs folliowing?
public clas myclass (
public static void main (String args) (
System.out.println( "hello world") ;} }
a) compilation error b) hello wold
c) Hello world d) Hello World
m)ink k = 5;
System.out.println ("Hello"+ k 5)
a) Hello 10 b) Hello 55 c) Hello 10
d) compiler error
) int p 3, q 6;
System.out.println (p ++* q);
a)9 b) 10
c) 11
d) compiler error
v) int p z
3
For
(p 0; p <
10; p p +
2)
System.out.println
a) 02468
(p);
b) 2 468
c) 10
Vi) int x d) 468 10
=
2;
for ;
x< 5:)
Systa)2.em.34out.println(j+*);
b) compiler error
c) runtime error
d) infinite loop
MCA JAVA-150
OBIECT ORIENTED PROGRAMMING WITHJAVA
al j1 =(1, 2, 3, 4, 5)
al
int
vil)
S y s t e m . o u t
intln (a . length)
a) 5 b) compiler error
to import:some package d) runtime error
c)need
String
1 ="java"
i) m.out.println (s1.indexof ("v'))
System.
b) 2 c) 3 d) none of these
a) 1
tem.out.
printl (s.charAt (0)
b) h c) error d) none of these
a) H
n Java
Applet, start( ) method may be invoked
) c) many times d) none of these
a) once
b) twice
stands for
xi) JVM Java Visual Machine
Machine b)
a) Java Vitual
Machine d) none of these
c) Java Vision
to define a constant?
Xi) Which keyword is used in java d) None of these
b) Final c) Public
a) Static
(Short
Answer Type Questions)
'method'&'constructor.
Define copy constructor.
between
constructor? Differentiate No. 18.
nat is Question
0pic: CLASSES AND OBJECTS, Short Answer Type
class?
What is wrapper
Give example.
3.What do you mean by 'Class& 'Object?
Answer Type
Question
No. 19.
See Topic: CLASSES AND OBJECTs, Short
of applet? Explain.
4.What different states in the life cyclenuestion No. 1.
e)Threadpriority
JAVA
FUNDAMENTALS,
eea INHERITANCE AND
b )S e e T o p i :
Loug Answer Iype
Question No. 2(»).
Se POLNMORruISM,
(LASSES OBIECTS, Long
AND Long
cSee
Answer Type
Answer Type Question No. 4(d).
INH
See
Topie:AND INHERITANCE
e T1READS, Long Answer POLYMORPHISM, Question No.I
d)
e)See Topie: Long Answer Type uestion
Type Question No. 8(b). No, 4(b).
QUESTION 2017
Group- A
(Multiple
1Choose
the Correct alternatives for any tenChoice Type Questions)
of the
Consider the following statements: following
int a 3, b 2
a (a<b) ? (a + b)(a -b);
what will be the output of a?
a) 5 b)-1 c 1 d) 3
Ahichlass
i)Wh can be used to read data line
by line using the
a) BufferedReader
readLine()
method?
b) InputStreamReader
c) DatalnputStream
d) none of these
MCA JAVA-153
POPULARPUBLICATIONS
in Java?
part of method signature
veWhich ofthe following is used as a c) Throws
a) Throw b) Try d) Finally
Which ofthe following is used to detect the selecion made by a user on a Choice co a Choice Componen
a) ActionListener b) ItemListener c) MouselListener
d) SelectionListens
Group B
2 (Short Answer Type
Why main() method of a Java Questions)
program be declared "static' and
See Topie: CLASSES AND OBJECTS,
Short Answer public"?
Type Question No. 21.
3. Explain the private,
Part: protected, public modifiers in brief.
What is the function
SeeTopie: CLASSES AND of finaily?
r Part: OBJECTS, Short Answer
See
Type Question No. 14.
Topic: EXxCEPTION
HANDLING, Short Answer
4
Write a Java Type Question No. 2.
program that
he folioving methods creates a child
thread of main using
See getNarme()
Topie: Runnable interface and the
THREADS, Short Answer i) setName)
Type Question No.
8(i) & (ii).
MCA JAVA-154
in Java
P O P U L A RPUBLICATIONS
keyword
Answer
stion No.9.
Iype Q u e s s
super Short
the MORPHISM,
m p l e n e n t
c o d e to
Java POLY
Wite a
INIHERITANCE AND
)
lopie: following
See
three ofthe
o n any
notes
short communicaton
Write
11
process
a) inter toolkit
window
Abstract
bc Wraprer ciass
d)Dynamicmethoddispatch
Question
No. 2(b).
1ype
e)Mult-develInheritance
Answer
Long 121d).
Topic:
JAVA FU Anner
Iype lype Question
Answer
.4(e).
See
Iong
APPLETS
Long Type
bSee Tope: ORJECTS,
LongAnswer Question N.
(LASSES
4ND POLYMORPHISM,
Type 4
c
See Topie: INHERITANOE AND POLYMORPHISM,
LongAnswer
dSee Topic: AND
INHERITANCE
Tnpic:
e)See
QUESTION 2018
Group-A
Questions)
Choice Type
(Multiple
following:
ten of the
alternatives any
corect
the
1 Choose
0 nt i=0;
i«14;
i++) [
for (int
f(i10
j-2i
"i:" +i);
S y e t m . o u t . p r i n t l n
("j;" +j+
code?
What is wrong
with the above
notinitialized
a) Integer T is
b) Nothing declaration
the for-loop
declare integer i inside
c) You cannot
"f statement is incorrect
d) The syntax of the them to strings
values without converting
e) You cannot print integer
MCA JAVA-156
OBIECT ORIENTED PRoGRAMMING WITHJAVA
trect cless MyApplet extends java apet Appletf
Abstract e
e ) C l a s s MyAppie
implements Appiet(
lues
va
l
[1
u e s
(1, 2, 3, 4, 5, 6, 7, 8):
ie X;
int
i int 1*0;
for
Syete
out print în (values fi}}
Rpfemingt o
the above What value for X wil print all members of array"values?
b) 7
c)8 d)9
ne sinoe
e) None. since there is a syntax error in the array declaration
string s='g*
statements:
following
viConsiderthe
nt all new int [3]:
a13)=7;
System.out.println (a[3])
The output is d) Runtime exception
c) Compile error
b) 7
a) 3
be initialized?
vil Which class cannot c) Final
d) Protected
b) Public
a) Abstract
code to
o) The JVM compiles a java source c) Unicode
d) None of these
b) Executable code
a) Object code
MCA JAVA-157