0% found this document useful (0 votes)
5 views11 pages

java mcq

The document contains multiple choice questions and answers related to Java programming concepts, including data types, object-oriented programming, and control structures. It also includes review questions that prompt explanations of various Java topics. The questions cover a range of topics from basic syntax to more advanced concepts in Java programming.

Uploaded by

giteshjare5933
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views11 pages

java mcq

The document contains multiple choice questions and answers related to Java programming concepts, including data types, object-oriented programming, and control structures. It also includes review questions that prompt explanations of various Java topics. The questions cover a range of topics from basic syntax to more advanced concepts in Java programming.

Uploaded by

giteshjare5933
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Multiple Choice Questions

Q.1 bytes = 16 bits.


(a) (b) 2 (c) 3 (d) 4

Ans. :(a)

Q.2 is the prOcess of binding data together.


(b) Object (c) Marshalling (d) Encapsulation
(a) Polymorphism
Ans. : (d)

Q.3 After successful compilation, the Java classes generates


executable files (d) references
(a) Objects (b). bytecodes (c)

Ans. : (b)

Q.4 What is "out" in statement [Link]()?


(c) interface (d) function
(a) class name (b) object/instance

Ans. : (b)
of,
Q.5 Java performs input output operations in form
(c) Constants (d) library
(a) String (b) integers
Ans. :(a)
program?
Q.6 Which Java package is already imported in every Java
[Link] (c) [Link] (d) [Link]
(a) [Link] (b)
Ans. : (d)

Q.7 What is range of datatype byte" in Java?


-64 to + 63 (d) - 128 to + 127
(a) -8to +7 (b) -16 to + 15 (c)
Ans. : (d)

Q.8 Java is a typed language.


none of these
(a) Weakly (b) strongly (c) moderate (d)
Ans. : (b)

Q.9 In Java, the datatypes int, long, byte, and short are
none ofthese
(a) signed (b) unsigned (c) both of these (d)

Ans. :(a)
Q. 10 Which of the following are legal lines of Java
code?

1. int w = (int)888.8; 2 byte x = (byte) 100L;


3. long y = (byte) 100; 4. byte z = (byte) 100L;
3and 4 (d) all of these
Iand 2 (b) 2 and 3 (c)
(a)
Ans. : (d)
functions?
Q. 11 Which of the datatyped value is returned by all transcendental math
(a) int (b) float (c) double (d) long
Ans. :(c)
0. 12 What willbe the output of following program?
class increment

publicstatic void main(String ar[ ])

int g=3;
[Link](++g * 8);

(a) 25 (b) 24 (c) 32 (d) 33


Ans. : (c)
Q. 13 Which of these coding types is used for data type characters in Java?
(a) ASCII (b) UNICODE (c) ISO-LATIN-1 (d) None of the mentioned
Ans. :(b)
0. 14 Which one is a valid declaration of a boolean to assign
false?
(a) boolean b=0; (b) booleanb='false':
(c) Both of these (d) None of these
Ans. :(d)

ReviewQuestions
Q.1 Explain data hierarchy. (Refer Section 1.3)
Q. 2 Explain different types of languages in brief. (4 Ma
(Refer Section 1.5)
Q. 3
Differentiate between OOP and POP. (Refer Section 1.6) (4 Ma
Q. 4 List the features of OOP and (3 Ma
explain any two. (Refer Section 1.6)
Q.5 Show the architecture of Java (6 Ma
Q. 6
applications. (Refer Section 1.9.2)
Which types of applications can be (2 Ma
Explain JVM, JRE and JDK. (Refer implemented using Java? (Refer Section 1.9.3)
Q.7 by
Sections 1.9.4, 1.9.5 and 1.9.6) (3 Ma
Q. 8 List the JDK tools which
smal description on each. (6 Ma
Q.9 What is (Refer Table 1.9.3)
CLASSPATH?How to set environment (2Ma
Output
Original: demol23 @[Link]
Uppercase: DEMO123@[Link]
Lowercase:demol23@[Link]
Multiple Choice Questions

Q.1 An object occupies memory.


(a) true (b) false
Ans. :(a)

Q.2 We can declare maximum numbers of objects in one Java program.

(a) 16 (b) 32 (c) 64 (d) any


Ans. : (d)

Q.3 executes automatically when object is declared.


main method (b) package (c) constructor (d) finalize
(a)
Ans. : (c)
Object-Ornented Prog1amming using Java (Dr. BATU) 231 Introduction to Claaso0, Objecta,
Q.4 A String can be converted into a
Methodn and
character array by using method,.
(a) convertToOAray( ) (h) to haracterArrayt )
(c)
convertToCharAray( ) (d) toCharArrny( )
Ans. : (d)

0.5 The default value of boolean


datanember is
(a) true (b) false
Ans. : (b)
Q.6 Java uses threads to enable the
entire environment to be
(a) symmetric (b) asymmeric (c) synchronous (d) asynchronous
Ans. : (d)

Q.7 Which of the following is/are true about


constructors in Java?
1. Constructor name should be same as class name.
2. If you don't define a constructor for a
class, a default parameter-lcss constructor is
the compiler. automatically created by
3. The default constructor calls super() and
initializes all instance variables to default value like 0, null.
4. If we want to parent class
constructor, it must be called in first line of constructor.
(a) 1only (b) land 2 both (c) land 3 both (d) all of above
Ans. : (d)
Q.8 In Java, can we make functions inline like
C++?
(a) true (b) false
Ans. : (b)
0.9 Which class is known as cosmic super
class in Java?
(a) class Array (b) class String (c) class
Object (d) class Vector
Ans. : (c)
Q. 10 What will be the output of following
program?
class mainclass

public staticvoid main(String ar[ )

boolean varl = true,


boolean var2 = false;
if (varl)
[Link](varl ):
else
and
Class9s, Objects,Methods
Introductlonto
3Object-Ortented Programnning using Java (Dr. BATU) 232
[Link]( var2),

(d) false
(a) (b) (e)

Ans. :(c)
condition for automatictype converNion in Java?
0. 11 Which of these is ncvessary
(a) The destination type is snaller than source type.

(b) The destination type is larger than source type.


source type.
(c) The destination type can be lurger or smaller than

(d) None of the mentioned.

Ans. : (b)
Java?
0. 12 What is Truncation is
(a) Floating-point valuc assigned to an integer type.
(b) Integer value assigned to floating type.
(c) Floating-point value assigned to an Floating type .
(d) Integer value assigned to floating type.
Ans. : (a)
return statement in it?
13 Which of these data type can be used for a method having a
0. both int and float
(b) int (c) float (d)
(a) void

Ans. : (d)
Review Questlons
(Refer Section 2.2)
members of a class? Explain their role in class definition.
Q. 1 Which are
Section 2.3)
Explain with simple example. (Refer
a.2 How to declare objects in Java ?
parameters ? Explain with an example. (Refer Section 2.4)
a.3 How to define a method with (Refer Section 2.4)
method requires parameters? Explaln with an example.
a. 4 Why does a
(Refer Section 2.5)
Q.5 Define instance variables. Section 2.6)
setter-getter methods. Explain it with an example. (Refer
a.6 Explain the applications of
object ? (Refer Section 2.7)
a.7 What is reference? How itdifHers from example case study.
constructo? How to initializo objects by using constructor? Explain with
Q.8 What is
(Refer Section 2.9)
datatypes?
floating point constant values are dltferentlated when initializing to float and double
Q.9 How
(Refer Section 2.10)
Object-Oriented Programming using Java (Dr. BATU) 3-39
Multiple Choice Questions
Control Sats
Q.1 In Java, Can evaluate any type of boolean
(a) switch, if
can only test for equality, whereas
(b) if, switch (c) if, break (d) continue, if expres ion,
Ans. : (a)
Q.2 Which of the following form of for loop willgo to infinite looping?
(a) for(; :) (b) for(i=0; i<l;i-) (c) for(i=0; ;it+) (d) Allof these
Ans. : (d)
Q.3 Which of the following can be used when numbers of iterations are already known?
(a) counter controlled repetition (b) sentinel controlled repetition
(c) exit controlled repetition (d) none of these

Ans. :(a)
Q.4 && is operator. whereas & is operator.
(a bitwise, logical (b) logical, bitwise
(c) bitwise, arithmetic (d) arithmetic, bitwise
Ans. : (b)
0.5 An if statement can have multiple else blocks.
(a) true (b) false
Ans.: (b)
Q.6 What will be the output of following program?
class Output

staticvoid main(String ar[ ])

int x, y=1;
X= 10;
if(x != 10 && x/0==0)

[Link](y):
else

[Link](++y);

(a) 1 (b) 2 (c) Compile-time error (d) Runtime enror


Ans. : (c)
Object-Oriented BAIU)

0.7 What will be the output of following program?


class Test

public static void main(String arfD

int i;
for(i=l;i<b;i4+)

if(i>3)continue;

[Link](i);

2 (b) 3 (c) 5 (d) 6


(a)
Ans. :(d)

0.8 What will be the output of following program?


class Test

public static void main(String arf ])

int i-0, j=5;


for( : (i<3) && (j++<10); it+)

[Link](" "+i+" *+ j);

[Link](" "+i+" "+j);

06172839
(a) 06172 838 (b)
06152535 (a) Compile-time error
(c)
Ans. : (a)
Q.9 What willbe the output of following program?
class Test

public static void main(String ar[)

int i,j;
for(i=l,j-0;i<10; i++)
Object-Urlel
j+=i;
[Link](i);

None of these
(d)
10 (b) 11 (c)
(a)
Ans. : (a)
output of following program?
Q. 10 What will be the
class Test

public static void main(String ar[ ))

int x=3, y=4;


switch(x+3)
{
case 6: y=0;
case 7: y=1;
case 8 : y += 1;

[Link](y);

(a) (b) 1 (c) 2 (d) 3


Ans. : (c)
Q. 11 Choose the correct options in
context with following program.
class Test

public static void


main(String ar[ ))
double sum=0;
for(doubled= 0; d<l0;)
dta 0.1;
sumt= sum + d;
foundin
not
R63
Multiple Choice Questions
Java, arTay are

objects (b) primitive datatypes


(a)
classes (d) none of these
(c)
Ans.: (a)
array declaration?
a1 Which of thefollowing is a valid
(a) char[ ] c = new char(5); (b) char( ) c = new char[5];

(c) char( ) c = new


char(5); (d) char[ ]c = new char[S];

Ans. : (d)
to a method, the method receives
0.3 When you pass an array element
(b) a copy of first
(a) a copy of array
(d) the length of array
the reference of array
(C)
Ans. : (c)
thefollowing is FALSE about arrays on Java?
Q.4 Which of
always an object.
(a) Ajava array is creationof array.
changed after
array can be
(b) Length of heap.
Java are always allocated on
(C) Arrays in
Allthe these.
()
Ans. : (b)
output of followingprogram?
Q.5 What will be the
class array_output

public static void main(String ar( ])

char array_variable [ ]= new char( 10);


for (int i =0; i< 10; ++i)
variable[i]='i;
array_v
[Link](array_variable[ i]+"";

itt;

(a) iiiii (b) 01234 (c) ijklm (d) None of these


Ans. : (a)
0.6 What is the output of this program, if we run as "java main arguments 123"?
class main_arguments

public static void main(String ar[ ] )

String[ J[] argument =new String[2][2];


int x;
argument[0] = args;
X= argument[0].length;
for (int y =0; y<x; y+t)

[Link](" " + argument[OJ[y]);

(a) 11 (b) 10 (c) 103 (d) 123

Ans. : (d)
0.7 What will be the output of following statements?
int arr[ ]= new int [(5];
[Link](arr);
(a) (b) value stored at arr[0]

(c) null (d) class_ name@hashcode

Ans. : (d)
0.8 Which of these is an incorrect Statemnent?
(a) It is necessary to use new operator to initialize an array.
(b) Array can be initialized using comma separated expressions surrounded by curly braces.
Array can be initialized when they are Array
(c) declared.
(d) None of the mentioned.
Ans. :(a)
these is
Q9 Which of necessary to specify at time of array
Row (b)
initialization?
(a) Column (c) Both Row and Column (d) None of the mentioned
Ans.: (a)

,10 What will bethe output of following program?


class array_output

public static void main(String ar[ J)

int array__variable[ ]= new int[10];


for (int i=0; i< 10;+i)

array_variable[i] = i;
[Link](array_variable[i] + " ":
i+;

(c) 0123456789 (d) 123456789 10.


02346 8 (b) 13579
(a)
Ans. : (a)
following program?
Q. 11 What will be the output of
class evaluate

ar[ 1)
publicstatic void main(String

5, 6, 7, 8, 9};
int arr[ ]={0, 1,2, 3, 4,
int n = 6;
n= ar[ana]/21:
[Link](arr[n] / 2);

(c) 6 (d) 1
(a) 3 (b)
Ans. : (d)

You might also like