Java Fundamentals: X (X ) ? (Y+x) : (Y-X)
Java Fundamentals: X (X ) ? (Y+x) : (Y-X)
JAVA FUNDAMENTALS
Multiple Choice Type Questions
1. Consider the following statements: WBUT 2006)
int x=10, y= 15;
x=(x<)?(y+x):(y-x);
what will be the value of x after executing these statements7
a) 10 b) 25 c) 15 e) Error, cannot be executed
d) 5
Answer: (6)
2. Which of the following are valid array declarations! definitions? WBUT 2008]
1) int iArray 2[1;
2) int iArrays[] new intf10];
3) int iArray4 (10) new int[10]:
a) 1 b) 2 c)3 d) none of these
Answer: (6)
5. JVM iss
WBUT 2010, 2018]
a) A java package b) A java compiler c) A system software
e) None of these
d) A java interface
Answer: (c)
Referring to the above, what classes can access method getSquare () in Class
A?
a) class A
b) class A and classes in package B only
c) class A, all subclasses of A and
classes in package B only
d) class A and its subclasses only
Answer: (b)
stands for
16. JIT WBUT 2013]
a) Just-in-time compiler b) java in time compilation
c)java interpreter timer
d) none of these
Answer: (a)
18. What is the result of attempting to compile and run the program> WBUT 20141
public class Test {
public static void main(String Ii args)
int x = 0, y = 0;
x =
5+ y++;
System.out.print ( x + " +y)
x = 0;
Y =0
5+++Y}
S y s t e m . o u t . p r i n t( x + " +y);
//end of main
W/end of test class
a) 5161 b) 6161 c) 671 ) none of these
Answer: (a)
MCA JAVA-7
POPULAR PUBLICATIONS
WBUT 2016
19. int i 2
("welcome"i + 2)1
Outprintln
The output is c) compilor orror d) nono of
thes
a) wolcome 4 b) wolcome 22
Answer: (c)
programs roo
will compile and run the WBUT 2016
at happon when vou
c) Hello world
Answer: (a)
Machine
WBUT 2016
21. JVM stands for Visual
b) Java these
a) Java Virtual Machine
c) Java Vision Machine
d) none of
Answer: (a)
WBUT 2016)
to define a constant? d) None of these
22. Which keyword is used in java c) Public
a) Static b) Final
Answer:(b)
the readLine() method?
data line by line using [wBUT 20171
Z3.
Which class can be used to read InputStreamReader
b) these
a) BufferedReader
d) none of
c) DatalnputStream
Answer: (c)
WBUT 2017, 2018]
Java source code to d) none of these
a
24. The JVM compiles c) Unicode
executable code
a) object code b)
Answer: (d)
WBUT 2018]
25. JRE stands for Engine
Engine
b) Java Remote
a) Java ResearchEnvironment d) None of these
Runtime
c) Java
Answer:(c)
Questions
ShortAnswer Type
WBUT 2006]
structure.
1. Draw the Java heap
Answer: data area from which memory
for all class
that is the runtime
The JVM has a heap JVM start-up.
allocated. lt is created at the
instances and arrays are
with the following VM options:
The heap size may be configured
-Xmx<size> - the maximum Java heap size
to set
MCA JAVA-8
OBJECT ORIENIED PROKGRAMMING WIIH JAYA
OPERATORS AND FLOW OF CONTROL
Multiple Cholce Type guestions
. int i WBUT 2009, 2010, 2018]
int i0 i<14; i*+)
if(i«10}
i2i
Which access modifier is used to restrict the methods scope to itself and stil
allows other classes to subclass that class$? WBUT 2009
)private b) final c) protected d) final
Answer: (C)
Answer: (d)
MCA JAVA-17
POPULAR PUBLICATONS
5. Consider the following statements: WBUT 2
int a-15, b«20
a((acb) ? (a+b):(a-b))
nat will be the value of a after executing these stato
c) 15
a) 10 b) 25 be executed
d))5 o) orror, c a n n o t
6. int a -
2
for (a 5 a + *)
System.out.println (a)i
7. int i = 2 i);
(i WBUT 2015
+++
System.out.println
The output is
b) 7
a) 3 d) runtime exception
c) compiler error
Answer: (d)
9. ink k = 5
WBUT 2016
+ k + 5)
Systea.out.println ("Hello"
The output is
a) Hello 10 b) Hello 55 c) Hello 10 d) compiler error
Answer: (b)
= 3, q = 6;
WBUT 2016]
10. int p
System.out.println (p + + + q)i
b) 10 c) 11 d) compiler error
a) 9
Answer: (a)
2 .class A
int i , i, k WBUT 2007]
public A (int ii) ti =
ii; )
public A )
k 1
3. Objects can be cast to another class when which among the following is case?
a) Both classes are direct subclasses of the same, superclass
b) The source class is not abstract or static
WBUT 2007]
c)The target class is a subclass of the,source class
d) Both classes are subclasses of the same abstract superclass
Answer: (c)
5. class A {
[WBUT 2008]
int i, j, k;
public A (int ii) t i = ii; }
public A )
k=1
a) int b) void c)
Answer: (d)
keywords relate to?
WBUT 2009
8. What do the 'public' and 'private' b) garbage collection
and (b)
c) both (a)
these
d) none of
Answer: (a) that the
code segment (assuming
the following
the output of WBUT 2012]
12. What will be address location 2345)?
stored in the
object 'ct' gets Test (
class Class
public string to
String ( ) }
return
" c l a s s Test ";
args) {
public static void main (String [
class Test ct
=
new Class Test ();
System.out.println (ct);
MCA JAVA-22
OBJECT ORIENIED PROGRAMMING WITHJAYA
al Class
Test @2345
b) Error
h)A WRONG PROGRAM
Ansmer: ( b ) ,
CODE
c) Class Test
d) ct
Wnticstatement
h about
static
3
inner classes may inner classes is tru? WBUT 2012]
aatic inner classes may access any of the enclosing
classes members
Datic inner classes do notnothave
c) stati
be Instantiated
outside of the enclosing class
ner
d) static inner. classes are
a reforenco to the enclosing class
created when the
tnswer: (d) enclosing class is loaded
default' access applies
14.
package only
a) with
cl the same as public access b) across all packages wBUT 2013]
Answer: (a) d) none of these
15. A
static member of a class
a) can be accessed in all main() methods WBUT 2013
b) can be accessed only outside main()
c)c a n be methods
accessed only in main() methods
d can be only accessed in one
that are static
main( ) method in any one
Answer: (c) program
MCA JAVA-23
POPULARPUBLICATIONS
18. What will bo the output WBUT 2014
class A
String sl "A.n1")
String s2 "A.s2"
Class B extends A
String sl "B.s1"
main (String [] arga) (
s t a t i c void
public class Test ( \public
B b1 new B()
A a1 bl;
S y s t e m . o u t . p r i n t l n ( a l . s 1 + " " + a 1 . a 2 )
/end main
class d) none of those
//end of test
b) B.s1 A.s2 c) A.s1 B.s1
a) A.s1 A.s2
Answer: (a)
syst.em.out.print (name)
E
pub
Btatic void m() (
Bx1 new B("X")
By1 new B("y")
S y s t e m . g o ( )
//ond of main
test clase
}//end o f
class
ofa methods
Contract
is meant by WBUT 2015, 20171
22. of in the class b) number of data fields in the class
number
constructors in the class d) none of these
Answer: (a)
Which one ofthe following cannot be used as a method modifier? WBUT 2017]
a) Private
b) Generic c) Protected d) Synchronized
Answer: (d)
MCA JAVA-25
OBJECI ORIENIED PROGRAMMING
WITH IAYA
b)
a) resolving multilevel inhe
eritar anomaly
c) resolving multiple inheritance anomaly
none
of these
d)
Answer: (a)
d All of these
Answer: (c)
MCA JAVA-55
OBJECT ORIENTED
PROGRAMMING WITH JAVA
STRING AND STRING BUFFER
Multiple Choice Type Questions
h of the following describes the
1. W h i c h
difference between
? StringBuffer and
GtringtriagBuffer is used only to buffer data from an input or output stream
a )S t r WBUT 2007, 2008]
b)
Buffer
StringBut allows text to be
changed after instantiation
holds zero
length strings
StringBuffer
StringBuffer
d supports Unicod
4nswer:
(b), (c) and (d)
these
e) none of
Answer: (c)
class is WBUT 2011
4. Difference between String and StringBuffer cannct be
be extendable but StringBuffer object
a) String object
can
MCA JAVA-79
POPULAR PUBLICATIONS8
6. What will be output:
NBUT 20
args) (
publio olass Test l
(String
main
Dublia s t a t i a void
Btring "
Buffer (),
Integerx 5 =
new
String
Buffer
sb
Btring
if (x 15)
.Goncat ( "Hi")
Byatem.out.print( s s b )
)//end of main
b) hello
//end of test olass
d) no output
a) HI
c) compllatlon error
Answer: (d)
WBUT 2015
6.String a"3"
System.out.println (a);
The output is b) a
d) runtime exception
a) 3
c) compiler error
a)H b)h
Answer: (a)
WBUT 2016
10. S t r i n g S="5"
System.out.println (s.charAt (0));
d) none of these
c) error
b) S
a) 5
Answer: (c)
MCA JAVA-80
OBJECT ORJENTED PROGRAMMING
WITH JAVA
ringBuffer diffe from 'String'?
H o wd o e s
oes
ngBuffer is used only to buffer data from an input or WBUT 2017]
StaBuffer holds allows text to be
changed after instantiation
output stream
GtringBuffer zero
length strings
aStrinBuffe supports Unicode
Answer:(b)
13 s t r i n g s e " s
.out.prinatln(s) WBUT 2018]
s t e a .
The output is
b) "s"
a) s c) Compile error d) Runtime error
Answer: (c)
Oafering
Refe to the above, when m1(2) is Invokod, m2() throws
Exception andd m1() returns which one of the following?
an
Arithmetic
a) 1 WBUT 2010]
b) 2
c) 3 d) 4
e) The system will exit
Answer: (a)
5. How you have a "try" block that invokes methods that throw two different
exceptions? WBUT 2012]
a) catch one exception in a "catch" block and the other in a "finally" block
b) setup nested "catch" blocks for each exception
c) catch one exception in a "catch" block and the other via the return value
d) include a "catch" block for each exception
Answer: (d)
MCA JAVA-87
POPULAR PUBLICATIONS
WBUT 201
6.What will be the output:
publie clans Tent ( a
publie etatic void main
(String
System.out.print ( " 1 " ) 1
try
returnn
(Except ion e)(
catch yBtem.out.print ("2")7
finally
System.out.print ("3")1
System.out.print ("4")
/ / e n d of main
class b) 14
) / / end of test
d) 13
a) 1234
c) 134
Answer: (d
WRIJT 2014
7. Given the following code
File f new File ( 'myfile.myfile.txt" to be in the
nderlying
created Und.
to De
the file "myfile.txt
will cause
method
operating system? b)f.closel):
a) f.write(); of these
d) none
c) f.flush();
Answer: (d)
o1
OBJECT ORIENIED PROGRAMMING
WITHJAVA
THREADSS
Multiple Cholce Type Questions
oad can bo accessed using
Doad
thre
ad
2 T h em e t h o d
USed in Java which waits for the thread to
die is
) b) destroy() WBUT 2007
al(a)
wait(
c) dief) d) join(
Ansner:(d)
WBUT 2007]
c)Synchronize d) None of those
Answer:(b)
6. The method used in Java which waits for the thread to die is WBUT 20111
a) waitt) b) destroy() c) diel) d) join)
Answer: None of the above. The join method waits for another thread to finish (not die).
MCA JAVA-99
OBIECT ORIENTED
PROGRAMMING WITH JAVA
APPLETS
Multiple Choice Type Questions
.mmediate superclass of the Applet class is
1. The
.shich one of
3 .Whi the following is a valid declaration of an applet?
a a) public class MyApplet extends java.applet.Applet
Java.applet.Appl { WBUT 2008, 2010, 2010
) public Applet MyApplet
Oublic class MyApplet extends Applet implements Runnable
c) public
d abstract class MyApplet extends java.applet.Applet(
d) abstract
Which code segment loads and plays a sound in an applet? WBUT 2012]
a) get Appilet Context ()-get Audioclip (new URL (get Document Base (). To
string ()+ "jawas.wav").start()
b) Play) getDocumentyBase (), "jaws.wav);
c) getAudioClip (new URL (getDocumentBase (). toString ()+ "fjaws.wav")).
Play ():
dget AppletContext (). Play Audio (new URL (getDocumentBase ( ). toString
()"jaws.wav"));
Answer: (a)
MCA JAVA-117