Date post: | 06-Jul-2018 |
Category: |
Documents |
Upload: | himan-jyoti-kalita |
View: | 235 times |
Download: | 0 times |
of 31
8/17/2019 Java programming moc test
1/31
1 Consider the following program:
public class ExceptionType {
public static void main(String
args!" { String s # null$
try
{ System%out%println(s%le
ngth(""$
&
catch(Exception e"
{ System%out%println('Excep
tion 1'"$
&
nally { try {
generateExcepti
on("$&
catch(Exception e"
{ System%out%println('Excep
tion )'"$
&
&
&
static void generateException(" throws *llegal+rgumentException{
throw new *llegal+rgumentException("$
&
&
,hich of the following statements are true regarding the above
given program- (Choose ."
+nswer: a% The output 'Exception )' is because of the
exception thrown programmatically
b% The output 'Exception 1' is because of the Exceptionthrown
programmatically
c% The output 'Exception 1' is because of the Exceptionthrown
by /0
d% The Exception thrown by generateException(" methodis an
2nchec3ed Exception
8/17/2019 Java programming moc test
2/31
e% The output 'Exception )' is because of the
Exception thrown by /0
) Consider the followingcode:
public class Except {
private void method1(" throws Exception {
throw new 4untimeException("$
&
public void method)(" {
try {
method1("$
& catch (4untimeException e"
{ System%out%println('Caught
Exception'"$
& catch (Exception e" {
System%out%println('Caught 4untime Exception'"$
&
&
public static void main(String
args!" { Except e # newExcept("$
e%method)("$
&
&
,hich of the following gives the correct output for the abovecode-
+nswer: a% 5o output
b% Compile time error
c% 6rints: Caught 4untime
Exception
d% 6rints: Caught Exception
8/17/2019 Java programming moc test
3/31
. ,hich of the following statements are true about String
+rrays- (Choose )" +nswer: a% +rray
index can be a long value
b% +rray index can be a negative
value c% String!! s # new
String7!!$
d% String!! s$
e% +rray decaration: String8!strarray$
9 Consider the following scenario:
The eneric;ruit class defines the following method to return afloat value:
public float calories( float serving " {
which
extends eneric;ruit> proposes to dene the following
overriding method:
public double calories( double serving " {
8/17/2019 Java programming moc test
4/31
parameter list%
8/17/2019 Java programming moc test
5/31
7 Consider the followingprogram:
public class TestStart implements 4unnable {
boolean stoper # true$
public void run(" {
System%out%println ('4un method Executed'"$
&
public static void main
(String! argv" { TestStart
ob=*nt # new TestStart("$
Thread thread? # new
Thread(ob=*nt"$ thread?%start("$
thread?%start("$
&&
,hat will be the output of the above program-
+nswer: a% Compiles and executes
successfully
6rints '4un method executed'
b% Compiles and on execution
6rints '4un method executed'then
throws 4untime exception
c% Compilation Error
d% Compiles and on execution
6rints '4un method executed'
8 Consider the following program:
class + extends Thread {
private int i$
public void run(" {i # 1$&
public static void
main(String! args" { + a #
new +("$
a%start("$
System%out%print(
a%i"$
8/17/2019 Java programming moc test
6/31
&
&
,hat will be the output of the above program-
+nswer: a% 6rints @
A Consider the followingcode:
import =ava%util%B$
public class Code1@ {
{
nal 0ector v$
v#new 0ector("$
&
public Code1@(" { &
public void codeethod("
{ System%out%println(v%isE
mpty(""$
&
public static void main(String args!" {
new Code1@("%codeethod("$
&
&
b% 6rints:
@1 c%
6rints: 1@
d% 6rints
1
e% Compiletimeerror
,hich of the following will be the output for theabove code-
+nswer: a% 4untime error:5ull6ointerException
8/17/2019 Java programming moc test
7/31
b% 6rints: false
c% Compilation error: cannot nd the symbol
d% 6rints:
true
e% Compilation error: v is not initialised inside theconstructor
D Consider the following code:
*n the following code method+ has an inner class
1% public class ase {)% private static nal int *F # .$
.% public String name$
9% public void method+( int nn "{
7% nal int serial5 # 11$
8% class inner {
A% void show4esult("{
D% System%out%println( '4slt# ' G ?? "$
H% &
1@% &
8/17/2019 Java programming moc test
8/31
H Consider the following scenario:
+ /ava application needs to stream a video from a movie le%
,hich of the following options gives the correct combination of
stream classes that can be used to implement the above
reJuirement-
+nswer: a% *nputStream4eader and
;ile*nputStream
b% ;ile*nputStream and ;ilter*nputStream
c% Kine*nputStream and uLered*nputStream
d% ;ile4eader and uLered4eader
e% ;ile*nputStream and uffered*nputStream
1@ ,hich of the following options are true about abstractimplementations in
Collections-(choose ."
+nswer: a% *t provides static factory class
b% +ll ma=or implementations li3e Mashtable>
0ectors are supported
c% They provide hoo3s for custom
implementations d% +ll ma=or interfaces
are supported
e% ap is not supported
11 Consider the following code:
class +T1 {
public static void main (String! args" {
byte! a # new byte1!$ long! b # new long1!$
8/17/2019 Java programming moc test
9/31
Noat! c # new float1!$ Ob=ect! d # new
Ob=ect1!$
System%out%print(a@!G'>'Gb@!G'>'Gc@!
G'>'Gd@!"$
&
&
,hich of the following will be the output of the above code-
+nswer: a% 6rints: @>@>@>null
b% 5one of the listed
options
c% 4untime error
d% 6rints: @>@>@%@>null
e% Compiletime error
1) Consider the following code snippet:
interface i1 {
int i # @$&
interface i) {
int i # @$
&
class inter implements i1>
i) { public static void
main(String! a"
{ System%out%println(i"$
&
&
,hich of the following options will be the output of the abovecode snippet-
a% 4untime Error
b% 6rints: @
c% 5o output
d% Compilation Error
8/17/2019 Java programming moc test
10/31
1. The following class denitions are in separate les% 5ote that the
,idget andig,idget classes are in different pac3ages:
1% pac3age conglomo$
)% public class ,idget extends Ob=ect{
.% private int my,idth$
9% ?????? void set,idth( int n " {
7% my,idth # n$
8% &
A% &
used in line 9 instead of
??????> would allow the ig,idget class to access the
set,idth method (as in line 1)"- (Choose )"
+nswer: a% nal
b% default (blan3"> that is> the method declaration
would read void set,idth( int n "
c% protected
d%private
e%public
8/17/2019 Java programming moc test
11/31
19 ,hich of the following statements are true regarding toString("
method-(Choose ."
+nswer: a% Feclared in the Ob=ect
class b% *t is polymorphic
c% Essential for inheriting a
class d% Fened in the
Ob=ect class
e% ives the String representation of anOb=ect
7 *t is possible to create a table using /FC +6*% State True or ;alse%
+nswer: True ;alse
18 Consider the following codesnippet:
import =ava%util%B$
public class TestColD{
public static void main(String
argv!"{ TestColD =un3 # new
TestColD("$ =un3%sampleap("$&
public void sampleap("
{ Treeap tm # new
Treeap("$
tm%put('a'>'Mello'"$
tm%put('b'>'/ava'"$
8/17/2019 Java programming moc test
12/31
tm%put('c'>',orld'"$
*terator it #
tm%3eySet("%iterator("$
while(it%has5ext(""
{ System%out%print(it%next("
"$
&
&
&
,hat will be the output of the above code snippet-
+nswer: a% abc
1A Consider the followingprogram:
public class Exp9 {
static String s # 'smileP%%'$
public static void
main(String! args" { new
Exp9("%s1("$
System%out%println(s"$
&
void s1(" {
try {s)("$
&
catch (Exception e" {
s G# 'morning'$
&
&
b% 4untime
error c% M,/
d% Mello/ava,orld
e% Compile error
8/17/2019 Java programming moc test
13/31
void s)(" throws Exception {
s.("$
s G# 'evening'$
s.("$
s G# 'good'$
&
void s.(" throws Exception {
throw new Exception("$
&
&
,hat will be the output of the above program-
+nswer: a%
smileP%%morningeveni
ng
b% smileP%%morning
1D Consider the following code snippet:
import =ava%io%B$
class Test {
int a # 1@$&
c% smileP%%
d% smileP%%eveningmorning
e%smileP%%morningeveninggood
class Test) extends Test implements SerialiQable {
int b$
public String toString(" {
return 'a # ' G a G '> ' G 'b # ' G b$
&
8/17/2019 Java programming moc test
14/31
&
public class *OCode7 {
public static void main(String args!" throws
;ile5ot;oundException> *OException>
Class5ot;oundException {
Ob=ectOutputStream out # new Ob=ectOutputStream(new
;ileOutputStream('C:
8/17/2019 Java programming moc test
15/31
)@ Consider the following code:
public class Kabeledrea3) {
public static void main(Stringargs!" {
loop:
for(int =#@$ =R)$ =GG" { for(int
i#@$ iR1@$ iGG" {
if(i ## 7" brea3
loop$
System%out%print(i G ' '"$
&
&
&
&
c% =ava%lang
d%
=ava%lang%annotati
on
e%=ava%sJl
,hich of the following will be the output for the above code-
+nswer: a% @ 1 ) . 9 @ 1 )
. 9
b% @ 1 ) . 9 7
c% @ 1 ) . 9
)1 Consider the following codesnippet:
abstract classFirector {
protected St
ri
8/17/2019 Java programming moc test
16/31
ng name$ d% 1 ) . 9 7
e% *ndenite Koop
8/17/2019 Java programming moc test
17/31
Firector(String name" {
this%name # name$
&
abstract void occupation("$
&
class ;ilmFirector extends
Firector { ;ilmFirector(String
name" { super(name"$
&
void occupation(" {
System%out%println('Firector ' G name G ' directs lms'"$
&
&
public class TestFirector {
public static void main(String! args" {
;ilmFirector fd # new ;ilmFirector('anirathnam'"$
fd%occupation("$
new Firector('anirathnam'" {
void occupation(" {
System%out%println('Firector ' G name G ' also produces lms'"$
&
&%occupation("$&
&
,hich of the following will be the output of the above codesnippet-
+nswer: a% Compilation fails at TestFirector class
b% 6rints: Firector anirathnam also produces
lms
c% 6rints: Firector anirathnam directs lms
Firector anirathnam also produces lms
d% 6rints: Firector anirathnam directs lms
8/17/2019 Java programming moc test
18/31
e% 4untimeError
)) Felimiters themselves be considered as to3ens% State True or;alse%
+nswer: True ;alse
). Consider the following scenario:
+ company decides that it only wants to use the most popular
names for its products% ou have to give the number of
employees against each uniJue rst name%
,hich of the following four core interfaces is bestsuited for
implementing the above scenario-
+nswer: a% ap
b% Set
c% ueue
d% Kist
)9 ,hich of the following modifier cannot be applied to thedeclaration of a eld
(member of a class"-
+nswer: a% protected
b% private
c% nal
8/17/2019 Java programming moc test
19/31
d% public
e% abstract
)7 ,hich of the following class in =ava%sJl pac3age maps the SK
data types to /ava datatypes-
+nswer: a% /FCTypes
b% /FCSKTypes
c% 5o explicit data type mapping% +utomatically mapped
on
uery Call%
d% Types
e% SKTypes
)8 ,hich of the following codes will compile and run properly-
+nswer: a% public class Test1 {public static void main(" {
System%out%println('Test1'"$
&
&
b% public class Test) {
static public void
main(String! in"
{ System%out%println('Test)'
"$
&
&
c% public class Test. {
public static void
main(String args"
{ System%out%println('Test.'
"$
&
8/17/2019 Java programming moc test
20/31
&
d% public class Test9 {
static int main(String args!" {
System%out%println('Test9'"$
&
&
e% public class Test7 {
static void main(String! data"{
System%out%println('Test7'"$
&
&
)A Consider the following code:
public class ,rap*t {
public static void main(String! args" {
new ,rap*t("%testC(IaI"$
&
public void testC(char ch" {
*nteger ss # new*nteger(ch"$
Character cc # new
Character(ch"$
if(ss%eJuals(cc""
System%out%print('eJuals '"$
if(ss%int0alue("##cc%char0alue(""
{ System%out%println('E'"$
&
&
&
,hich of the following gives the valid output for the
above code- +nswer: a% 6rints: eJuals
b% Compiletime error: *nteger wrapper cannot accept
char type c%6rints: E
8/17/2019 Java programming moc test
21/31
d% Compiletime error: ,rapper types cannot be
compared using eJuals
e% 6rints: eJuals E
)D ,hich of the following statements are valid . dimensional
character array creations-(Choose )"
+nswer: a% char!!! char+rray # {{IaI> IbI&> {IcI>
IdI&> {IeI> IfI&&$ b% char!!! char+rray #
{{{IaI> IbI&> {IcI> IdI&> {IeI> IfI&&&$
c% char!!! char+rray # {{IaI> IbI&> {IcI> IdI&>
{IeI&&$
d% char!!! char+rray # new char)!)!!$
e% char)!)!! char+rray # {IaI> IbI&$
)H Consider the following class denition:
class *nOut{
String s# new
String('etween'"$ public
void amethod(nal int i+rgs"
{ int iam$
class icycle{
public void sayMello("{
%%%Kine 1
&
&
8/17/2019 Java programming moc test
22/31
,hich of the following statements would be correct to be
coded at %%%Kine 1- (Choose )"
+nswer: a%System%out%println(i+rgs"$
b% System%out%println(iam"$
c%System%out%println(iOther"$
d% System%out%println(s"$
.@ Consider s1 and s) are sets%
,hich of the following options gives the exact meaning of
the method call s1%retain+ll(s)"-
+nswer: a% transforms s1 into the union of s1 and s)
b% transforms s1 into the intersection of s1 and s)%
c% transforms s1 into the (asymmetric" set
difference of s1 and s)
d% copies elements from s) to s1
e% returns true if s) is a subset
of s1
.1 ,hich of the following annotations are dened in =ava%lang
pac3age- (Choose ." +nswer:
a% U S u pp ress,arn ing s
b% UTar g et
c% U4e t enti o n
mailto:@SuppressWarningsmailto:@Targetmailto:@Retentionmailto:@Retentionmailto:@Retentionmailto:@Targetmailto:@Retentionmailto:@SuppressWarnings
8/17/2019 Java programming moc test
23/31
.) Consider the following code:
class Test
{ Test(in
t i" {
System%out%println('Test(' Gi G'"'"$
d% UOverri d e
e% Udeprecated
&
&
public class uestion{
static Test t1 # new
Test(1"$ Test t) #
new Test()"$
static Test t. # new Test(."$
public static void
main(String! args"
{ uestion # new
uestion("$
&&
,hich of the following options gives the correct order ofinitialiQation-
+nswer: a% Test(."
Test()"
Test(1"
b% Test()"
Test(1"
Test(."
c% Test(1"
Test()"
Test(."
d%
Test(1"
Test(."
Test()"
mailto:@Overridemailto:@Overridemailto:@Override
8/17/2019 Java programming moc test
24/31
.. ,hich of the following methods is used to chec3 whether
4esultSet ob=ect contains records-
+nswer: a% rst("
b% has4ecords("
c% next("
d% last("
e% previous("
.9 ,hich of the following options are true about +ssociations-
(choose )" +nswer: a% *n +ssociations> cardinality refers
to the number of related
ob=ects
b% +ssociation refers to binding of related data andbehaviours
into a single entity
c% +ssociations are bidirectional
d% +ssociation refers to a class reuses the
properties and methods of another class
e% +ssociation refers to an ob=ect composed of set ofother
ob=ects
.7 Consider the following codesnippet:
class TestString9 {
public static void main(String
args!" { String s1 # '*ts
reat'$
String s) # '*ts Tric3y'$
System%out%print(s1%concat(s)"%length(" G ' '"$
8/17/2019 Java programming moc test
25/31
System%out%print(s1%concat(s)%substring(1> s1%length("""%length(""$
&
&
,hat will be the output of the following code snippet-
+nswer: a% 1D )@
b% 1A 1H
c% )@ 1D
d% 1A 1A
e% 1H 1A
.8 Consider the followingcode:
class 6lanet { &
class Earth extends 6lanet { &
public class ,elcome6lanet {
public static void welcome6lanet(6lanet planet" {
if (planet instanceof Earth"
{ System%out%println(',elc
omeP'"$
& else if (planet instanceof
6lanet"
{ System%out%println('6lan
etP'"$
& else {
System%exit(@"$
&
&
public static void main(String args!"{ ,elcome6lanet wp # new
,elcome6lanet("$ 6lanet planet #
new Earth("$
welcome6lanet(planet"$
&
&
8/17/2019 Java programming moc test
26/31
,hich of the following will be the output of the above program-
+nswer: a% +n exception is thrown at
runtime
b% The code runs with no output
c% ,elcomeP
d%6lanetP
e% Compilation fails
.A ,hat methods does the =ava%lang%4untime class provide
related to memory management-(Choose ."
+nswer: a% to invo3e arbage collector
b% to create new memory locations
c% to Juery the total memory and free
memory d% to dump the ob=ects to
storage device
e% to run naliQe methods explicitly
.D ,hich of the following statement is true-
+nswer: a% To call the wait(" method> a thread must own
the loc3 of the ob=ect on which the call is to bemade%
b% To call the yield(" method> a thread must own
the loc3 of the ob=ect on which the call is to be
made%
c% To call the sleep(" method> a thread must own the
loc3 of the ob=ect which the call is to be made%
8/17/2019 Java programming moc test
27/31
d% To call the wait(" method> a thread must own the
loc3 of the current thread%
e% To call the =oin(" method> a thread must own the
loc3 of the ob=ect on which the call is to be made
.H ,hich of the following statements are true-
(Choose )" +nswer: a% +ll exceptions are
thrown by /0
b% +ll 4untimeException are thrown by /0
c% /0 cannot throw userdened exceptions
d% +ll exceptions are thrown programmatically from thecode or
+6*
e% /0 thrown exceptions can be thrownprogrammatically
9@ Consider the followingcode:
public class 2nwiseThreads implements 4unnable {
public void run(" {
while(true"{ &
&
public static void main(String args!"
{ 2nwiseThreads ut1 # new
2nwiseThreads("$ 2nwiseThreads
ut) # new 2nwiseThreads("$
2nwiseThreads ut. # new
2nwiseThreads("$ ut1%run("$
ut)%run("$
ut.%run("$
&
&
8/17/2019 Java programming moc test
28/31
,hich of the following is correct for the above given program-
8/17/2019 Java programming moc test
29/31
+nswer: a% The code compiles and runs . non ending non
daemon threads
b% The code compiles but runs only 1 non ending> nondaemon
thread
c% 4untime Error
'*llegalThreadStateException' d%
Compilation error 'ut)%run(" is never
reached'
91 ,hich of the following options is true about multilevelinheritance-
+nswer: a% *nheriting from two super classes
b% *nheriting from a class which is already in an
inheritance hierarchy
c% *nheriting from more than one
super class d% *nheriting from a single
class
9) +nonymous class can have their own members%
State True or ;alse%
True ;alse
9. Consider the following partialcode:
interface + { public int get0alue("$ &
class implements + {
public int get0alue(" { return 1$ &
&
8/17/2019 Java programming moc test
30/31
class C extends {
when inserted
individually at the commented line ( C c)" {c1%get0alue("$ &
d% public void add(C c" { c%get0alue("$ &
e% public void add(+ a> b" {a%get0alue("$ &
99 ;rom /FV 1%8> which of the following interfaces is also
implemented by =ava%util%Treeap class-
+nswer: a%5avigableap
97 Consider the following code snippet:
class
5ode {
5ode
node$
&
class 5odeChain {
public static void main(String a!" {
b%
5avigableSe
t c%
5avigableKis
t d% FeJue
8/17/2019 Java programming moc test
31/31
5ode node1 # new 5ode("$