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

Java MCQ

1. The document discusses multiple choice questions related to Java concepts like classes, inheritance, exceptions, threads etc. 2. It asks about the output of code snippets involving inheritance, exceptions, threads and abstract classes. 3. It also asks about correctly and incorrectly declared methods in an abstract class, the result of trying to compile and run code with private methods and finalize, and the proper way to create child threads in Java.

Uploaded by

rony roy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
885 views

Java MCQ

1. The document discusses multiple choice questions related to Java concepts like classes, inheritance, exceptions, threads etc. 2. It asks about the output of code snippets involving inheritance, exceptions, threads and abstract classes. 3. It also asks about correctly and incorrectly declared methods in an abstract class, the result of trying to compile and run code with private methods and finalize, and the proper way to create child threads in Java.

Uploaded by

rony roy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

QUESTION 2014

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

a) 5161 b) 6161 d) none of these


c)671

What wil be the output


public class Test(

int i
public Test ()
System.out.println("Hello *" i = *+i) ;}

public Test (int w)


this():

public static void main (String args [])


Test obj = new
Test (50)
//end of maina
//end of test class

a) Hello i= 0 b) Hello i = 50 c) Compilation error d) none of these

)What will be the output


class A
String sl = "A.s1";

String s2 = A . S2";

Class B extends A{
String sl = *B.s1";
POPULAR PUBLICATIONS

i ar9s) (

static void main (string


public class Test ( \publ ic
Bbl = new B()
A al b l ;
s2)i
em.out.println
(al.s1+* *+al.
Syst
//end main
end of test class c)As1 Bs1 d none
a) As1As2 b) Bs1A s2

which are they?


v) Three of the methods are incorrectly declared,
abstract class abst ractA
public void testl0
public final void test2() 0:

public static void test3 () (0;


public abstract static void test4();
public abst ract final void test5(

a) test1, test2 and test4 b) test2, test4 and test5

c) test1, test4 and test5 d) none of these

v) What will be the output


abstract interface IOne{ 1/line 1
final int x = 100; 1/1ine 2
void m 10;
public stat ic class AOne{) 1/line3

a) compilation error at line 1


b) compilation error at line 2
c) compilation error at line 3
d) no compilation error
Question is not clear

vi) Which class declaration results in


class Z{ compilation error
void m() {

abstract class A //1ine 1


final class B
1/line 2
private class C( I/line 3
public class D )1/line 4

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

vilWhat is the resuilt of artempting to compile and run the program

class B(
private string name;
public B(String s){
name S;

protected void finalize () (


System. out.print (name) ;

class E
public static void m()
B x1 = new B("X");

B yl = new B("y"):

public class Test (


public static void main (String[] args)

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)

public ciass Test main


(String

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°);

else sb. append("Hello")

sb);
(s
System.cut.print

end of nain

end of test class


b) hello
c) compilation error
d) no output
a) H

Given the folowing code


File t new Filefmyfile bt")
in the underiying operating systema
What method wll cause the fie "myfile txt' to be created
a) f write0 b) fclosel) c)ffush: d) none of these
Group-B
(Short Answer Type Questions)
2 Why does Java two ways to create child threads (by extending Thread or implemn
Runnable) and which approach is better? enting
See Topic: THREADS, Short Answer Type Question No.7.

3 Distinguish between the following terms:


(a) Abstract Class and Interface
D) throws and 'throw
See Topic: INHERITANCE
AND
b) See POLYMORPHISM, Short Answer Type Question No. 17.
Topie: EXCEPTION HANDLING, Short
Answer Type Question No. 8.
4 What are the properties of
hep of an
a
constructor? Explain the use of
example overloaded constructors with the
"part: See Topic: INIIERITANCE
AND
part: See Topie: CLASSES POLYMORPHISM, Short Answer Type
AND
OBJECTS, Long Answer Question No. 18.
5 Wrte a
program in JAVA that
Type Question No. 4.
the following methods creates a Child
Thread of main
()getNamet) using Runnable interface ana Uses

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

Answer Type Question No.


3.
E\CEPIION
HANDLING, Long
bee Topic:
1HREAns, Long Answer Iype Question
No. 4.
cSee Topic: 2. No.
7HRE ADS, Short
tnswer Type Question
dl See lapic:
text area and
button. When
that creates a text field and you cick
ve

a) Wte an appicaton area. on tha


to the Text
is moved
contents of the text field
adt Button the heap?
aollection can be done in java
) How the gartage llustrate with an example.
diferent types oftheinner
class? that are sum
low and high of.
What are the
all integers
between the cube of the
W h t e a pragram
that displays
such that xyz
= x + y +z, for example 152
In
other words
find all numbers xyz
dgits
low and 1000 for high.
3Thy 100 for Question No.
10.

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

(Multiple Choice Type Questions)


alternatives for the following
1

Choose the correct

) 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

)compiler error b) runtime exception c) infinite loop d) 234

2
nt
y s t em. out print in (i

The output s

)4 c) 3 d) compiler error

n t arT [ l new int [3]

a7T(317:

ystem. out .println (arr[31)


The output is

a) 3 b) 7
c) compiler error d) runtime exception

vString s INDIA";

system.out.prnt In (s.charAt (2) ):


The output is

a) D b) 2 c) N d) exception occurs

vi An interface can define only


a) abstract class b) final field
c) abstract method d) abstract method and final field

vIR) Under which circumstances will a thread stop?


Select all valid answers
a) the run( ) method that the thread is executing ends
b) the cal to the start( ) method of the thread object returns
c) the suspend( ) method is called on the thread object
d) the wait() method is called on the thread object

u) Dynarnic method dispatcher is useful for


a) resolving method overriding b) resolving multilevel inheritance
c)resolving multiple inheritance anomaly d) none of these

MCA JAVA-147
POPULAR PUGLICATIONS

gUESTION 2016

GROUP-A

(Multiple (hoice Type Questions)


alternatives for any ten of the following.
1 Choose the correct
It 1s executed with
program when the commang
the
)What will be the output of the following
end
argument?
java contest how are you

class cont est (


1) {
public static void main(String argsl
Syst em.out.println (args(1] ); })
b) how c) are
a) contest d) you

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

ix) String s = " H e l l o

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

xi) string S="5"


System.out.println(s.charAt (0))
d) none of these
a) 5 b) S cerror
Group-B

(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

A constructor returms value of type


a) int b) void c) class type itself
d) nothing, as no specification of return type is needed

w) How does 'StringBuffer differ from 'String'?


a) StringBuffer is used only to buffer data from an input or output stream
'

b) StringBuffer allows text to be changed after instantiation


c) StringBuffer holds zero length strings
d) StrinBuffer supports Unicode

Which one of the following cannot be used as a method modifier?


a) Private b) Generic c)Protected d) Synchronized

Ihe JVM compiles a Java source code to


a) object code b) executable code c) Unicode 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

about an interface is incorrect?


vi)Which of the following statements
several interfaces
a) A parbcuier class can implement
b) tcan be implemented by an interface
C) tcan be implemented by several classes
d) t can be partialy implemented by a class

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

Contract of a dlass is meant by


a) number of methods in the class ,
b) number of data fields in the
class
cnumber of constructors in the class d) none of these

Consider the folowing statement


String s = "BCAD-6023";

System.out.print1n (s.chartAt (2))


The output is
a)c b) A c) Exception error
d) 2

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

QuestionNo. Q u e s t i o n No. 10(b),


NDAMENTALS,

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

is a valid declaration of an applet?


i) Which one of the following
a) Public class MyApplet extends java.applet Applet{
b) Public MyApplet
c) Pubic class MyApplet extends applet implements Runnable

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

nde declares cdas A to belong to the mypackage.financial package?

alpack.age a ckage: package financial, b) Import mypackage


financial. A d) Import mypackage.financial.
a mport mypackage
el package mypackage.financial;

package b) purchase consumption phase


a) 8 java
software d) All of these
c) A system

string s='g*

out .print ln (s)


syst em.
The output is
d) Runtime error
c) Compile error
b) "s

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

You might also like