SlideShare a Scribd company logo
MCQs BANK
Page: 1
Object Oriented
Programming
Topic: Loops
Instructions:
This MCQs Bank contains question
and solution on adjacent(even-odd)
pages. First try to solve the MCQ by
yourself, then look for the solution.
Best viewed in “single page view”
in PDF viewer.
MCQs BANK No.: 4
MCQs Bank on Object Oriented Programming
Topic : Loops
MCQ No: 1
Consider the following two
statement:
1: The while statement is a looping
construct that executes a block of
code while a condition is true.
2: The loop condition must be a
boolean expression.
a) Both 1 and 2 are TRUE
b) Only 1 is TRUE
c) Both 1 and 2 are FALSE
d) Only 2 is TRUE
Page: 2
MCQs Bank on Object Oriented Programming
Topic : Loops
MCQ No: 1 (Solution)
Ans: a) Both 1 and 2 are TRUE
Explanation:
The while statement is a looping
construct control statement that
executes a block of code while a
condition is true. You can either
have a single statement or a block
of code within the while loop. The
loop will never be executed if the
testing expression evaluates to
false. The loop condition must be a
boolean expression.
Page: 3
MCQs Bank on Object Oriented Programming
Topic : Loops
MCQ No: 2
In which loop the test is performed
at the end and the loop body
executes at least once?
a) while loop
b) for loop
c) do-while loop
d) all of these
Page: 4
MCQs Bank on Object Oriented Programming
Topic : Loops
MCQ No: 2 (Solution)
Ans: c) do-while loop
Explanation:
The do-while loop is similar to the
while loop, except that the test is
performed at the end of the loop
instead of at the beginning.
This ensures that the loop will be
executed at least once. A do-while
loop begins with the keyword do,
followed by the statements that
make up the body of the loop.
Page: 5
MCQs Bank on Object Oriented Programming
Topic : Loops
MCQ No: 3
Which of the following loop use this
looping construct
(<initialization>; <loop condition>;
<increment expression>)
a) while loop
b) for loop
c) do-while loop
d) all of the above
Page: 6
MCQs Bank on Object Oriented Programming
Topic : Loops
MCQ No: 3 (Solution)
Ans: b) for loop
Explanation:
The for loop is a looping construct
which can execute a set of
instructions a specified number of
times. It’s a counter controlled
loop. The syntax of the loop is as
follows:
for (<initialization>; <loop condition>;
<increment expression>)
<loop body>
Page: 7
MCQs Bank on Object Oriented Programming
Topic : Loops
MCQ No: 4
What will be the output of the
following program:
a) Infinite Loop
b) Hello
c) Compiler Error
d) Runtime Error
Page: 8
MCQs Bank on Object Oriented Programming
Topic : Loops
MCQ No: 4 (Solution)
Ans: c) Compiler Error
Explanation:
The code gives Compiler Error.
There is an error in condition check
expression of for loop. Java differs
from C++(or C) here. C++
considers all non-zero values as
true and 0 as false. Unlike C++, an
integer value expression cannot be
placed where a boolean is
expected in Java.
Page: 9
MCQs Bank on Object Oriented Programming
Topic : Loops
MCQ No: 5
What will be the output of the
following code?
// filename Test.java
class Test {
public static void main(String[] args) {
for(int i = 0; true; i++) {
System.out.println("Hello");
break;
}
}
}
a) Hello
b) Infinite times Hello
c) Compiler Error
d) Runtime Error
Page: 10
MCQs Bank on Object Oriented Programming
Topic : Loops
MCQ No: 5 (Solution)
Ans: a) Hello
Explanation:
The Program prints Hello 1 time only.
This is because although the
condition in the for loop is
true(always true) but there is a break
statement after the print statement,
which terminates the loop and
transfers the control outside the for
loop.
Page: 11
MCQs Bank on Object Oriented Programming
Topic : Loops
MCQ No: 6
What will be the output of the following
program:
// filename Test.java
class Test {
public static void main(String[] args) {
for(int i = 0; true; i++); {
System.out.println("Hello");
break;
}
}
}
a) Executes but no output
b) Prints Hello
c) Runtime Error
d) Compiler error: break outside
switch or loop
Page: 12
MCQs Bank on Object Oriented Programming
Topic : Loops
MCQ No: 6 (Solution)
Ans: d) Compiler error: break
outside switch or loop
Explanation:
If you note carefully there is a
semicolon just after the for loop.
This makes the for loop as do
nothing loop, because the for loop
body is terminated at the
semicolon.
Now, break statement must be
inside some loop block or switch-
case block. As the break statement
is not inside any loop body it
generates error during compilation.
Page: 13
MCQs Bank on Object Oriented Programming
Topic : Loops
MCQ No: 7
What will be the Output of the following
code?
// filename Test.java
class Test {
public static void main(String[] args) {
for(int i = 0; true; i++); {
System.out.println("Hello");
//break;
}
}
}
a) Executes but print nothing
b) Prints Hello
c) Compiler Error:unreachable statement
d) Runtime Error
Page: 14
MCQs Bank on Object Oriented Programming
Topic : Loops
MCQ No: 7 (Solution)
Ans: c) Compiler Error:
unreachable statement
Explanation:
In the for loop there is a semicolon
at the end of loop, which makes the
loop as do-nothing loop. Also the
condition of the loop is always true
which results in executing the blank
statement infinite times. The flow of
the program gets stuck at for loop
statement and the print statement is
never reached, as a result it give
“unreachable statement” error.
Page: 15
MCQs Bank on Object Oriented Programming
Topic : Loops
MCQ No: 8
What will be the output of the following code?
// filename Test.java
class Test {
public static void main(String[] args) {
for(;;) {
System.out.println("Hello");
break;
}
}
}
a) Hello
b) Compiler Error
c) Runtime Error
d) Print Hello infinite times
Page: 16
MCQs Bank on Object Oriented Programming
Topic : Loops
MCQ No: 8 (Solution)
Ans: a) Hello
Explanation:
All the sections in the for-loop
header are optional. Any one of them
can be left empty, but the two
semicolons are mandatory. In
particular, leaving out the <loop
condition> signifies that the loop
condition is true. The (;;) form of for
loop is commonly used to construct
an infinite loop.
In the for loop body there is a break
statement which terminates the for
loop.
Page: 17
MCQs Bank on Object Oriented Programming
Topic : Loops
MCQ No: 9
A _____________ stops the
iteration of a loop (while, do or for)
and causes execution to resume at
the top of the nearest enclosing
loop. Fill in the blank.
a) return statement
b) break statement
c) continue statement
d) None of these
Page: 18
MCQs Bank on Object Oriented Programming
Topic : Loops
MCQ No: 9 (Solution)
Ans: c) continue statement
Explanation:
A continue statement stops the
iteration of a loop (while, do or for)
and causes execution to resume at
the top of the nearest enclosing loop.
You use a continue statement when
you do not want to execute the
remaining statements in the loop, but
you do not want to exit the loop itself.
Page: 19
MCQs Bank on Object Oriented Programming
Topic : Loops
MCQ No: 10
Which among the statements
transfers the control of the program
out of the enclosing loop ( for, while,
do or switch statement).?
a) return statement
b) break statement
c) continue statement
d) None of these
Page: 20
MCQs Bank on Object Oriented Programming
Topic : Loops
MCQ No: 10 (Solution)
Ans: b) break statement
Explanation:
The break statement transfers
control out of the enclosing loop ( for,
while, do or switch statement). You
use a break statement when you
want to jump immediately to the
statement following the enclosing
control structure.
Page: 21
Ad

More Related Content

What's hot (20)

Multiple Choice Questions on JAVA (object oriented programming) bank 1 -- int...
Multiple Choice Questions on JAVA (object oriented programming) bank 1 -- int...Multiple Choice Questions on JAVA (object oriented programming) bank 1 -- int...
Multiple Choice Questions on JAVA (object oriented programming) bank 1 -- int...
Kuntal Bhowmick
 
Operators and Expressions in Java
Operators and Expressions in JavaOperators and Expressions in Java
Operators and Expressions in Java
Abhilash Nair
 
Oops Quiz
Oops QuizOops Quiz
Oops Quiz
Dr. C.V. Suresh Babu
 
Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)
slire
 
Java programming course for beginners
Java programming course for beginnersJava programming course for beginners
Java programming course for beginners
Eduonix Learning Solutions
 
React for Beginners
React for BeginnersReact for Beginners
React for Beginners
Derek Willian Stavis
 
Java constructors
Java constructorsJava constructors
Java constructors
QUONTRASOLUTIONS
 
Multiple Choice Questions on JAVA (object oriented programming) bank 7 -- abs...
Multiple Choice Questions on JAVA (object oriented programming) bank 7 -- abs...Multiple Choice Questions on JAVA (object oriented programming) bank 7 -- abs...
Multiple Choice Questions on JAVA (object oriented programming) bank 7 -- abs...
Kuntal Bhowmick
 
Exception Handling In Java
Exception Handling In JavaException Handling In Java
Exception Handling In Java
parag
 
This keyword in java
This keyword in javaThis keyword in java
This keyword in java
Hitesh Kumar
 
Java basic
Java basicJava basic
Java basic
Sonam Sharma
 
Lets make a better react form
Lets make a better react formLets make a better react form
Lets make a better react form
Yao Nien Chung
 
JUnit 5
JUnit 5JUnit 5
JUnit 5
Scott Leberknight
 
Java programming lab manual
Java programming lab manualJava programming lab manual
Java programming lab manual
sameer farooq
 
Final keyword in java
Final keyword in javaFinal keyword in java
Final keyword in java
Lovely Professional University
 
Java Deserialization Vulnerabilities - The Forgotten Bug Class (DeepSec Edition)
Java Deserialization Vulnerabilities - The Forgotten Bug Class (DeepSec Edition)Java Deserialization Vulnerabilities - The Forgotten Bug Class (DeepSec Edition)
Java Deserialization Vulnerabilities - The Forgotten Bug Class (DeepSec Edition)
CODE WHITE GmbH
 
JavaScript Event Loop
JavaScript Event LoopJavaScript Event Loop
JavaScript Event Loop
Designveloper
 
Complete Java Course
Complete Java CourseComplete Java Course
Complete Java Course
Lhouceine OUHAMZA
 
React js use contexts and useContext hook
React js use contexts and useContext hookReact js use contexts and useContext hook
React js use contexts and useContext hook
Piyush Jamwal
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
Pranali Chaudhari
 
Multiple Choice Questions on JAVA (object oriented programming) bank 1 -- int...
Multiple Choice Questions on JAVA (object oriented programming) bank 1 -- int...Multiple Choice Questions on JAVA (object oriented programming) bank 1 -- int...
Multiple Choice Questions on JAVA (object oriented programming) bank 1 -- int...
Kuntal Bhowmick
 
Operators and Expressions in Java
Operators and Expressions in JavaOperators and Expressions in Java
Operators and Expressions in Java
Abhilash Nair
 
Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)
slire
 
Multiple Choice Questions on JAVA (object oriented programming) bank 7 -- abs...
Multiple Choice Questions on JAVA (object oriented programming) bank 7 -- abs...Multiple Choice Questions on JAVA (object oriented programming) bank 7 -- abs...
Multiple Choice Questions on JAVA (object oriented programming) bank 7 -- abs...
Kuntal Bhowmick
 
Exception Handling In Java
Exception Handling In JavaException Handling In Java
Exception Handling In Java
parag
 
This keyword in java
This keyword in javaThis keyword in java
This keyword in java
Hitesh Kumar
 
Lets make a better react form
Lets make a better react formLets make a better react form
Lets make a better react form
Yao Nien Chung
 
Java programming lab manual
Java programming lab manualJava programming lab manual
Java programming lab manual
sameer farooq
 
Java Deserialization Vulnerabilities - The Forgotten Bug Class (DeepSec Edition)
Java Deserialization Vulnerabilities - The Forgotten Bug Class (DeepSec Edition)Java Deserialization Vulnerabilities - The Forgotten Bug Class (DeepSec Edition)
Java Deserialization Vulnerabilities - The Forgotten Bug Class (DeepSec Edition)
CODE WHITE GmbH
 
JavaScript Event Loop
JavaScript Event LoopJavaScript Event Loop
JavaScript Event Loop
Designveloper
 
React js use contexts and useContext hook
React js use contexts and useContext hookReact js use contexts and useContext hook
React js use contexts and useContext hook
Piyush Jamwal
 

Similar to Multiple Choice Questions on JAVA (object oriented programming) bank 4 -- loops (20)

Full solution manual for modern processor design by john paul shen and mikko ...
Full solution manual for modern processor design by john paul shen and mikko ...Full solution manual for modern processor design by john paul shen and mikko ...
Full solution manual for modern processor design by john paul shen and mikko ...
neeraj7svp
 
Solution manual for modern processor design by john paul shen and mikko h. li...
Solution manual for modern processor design by john paul shen and mikko h. li...Solution manual for modern processor design by john paul shen and mikko h. li...
Solution manual for modern processor design by john paul shen and mikko h. li...
neeraj7svp
 
Multiple Choice Questions on JAVA (object oriented programming) bank 5 -- mem...
Multiple Choice Questions on JAVA (object oriented programming) bank 5 -- mem...Multiple Choice Questions on JAVA (object oriented programming) bank 5 -- mem...
Multiple Choice Questions on JAVA (object oriented programming) bank 5 -- mem...
Kuntal Bhowmick
 
Control Flow Analysis
Control Flow AnalysisControl Flow Analysis
Control Flow Analysis
Edgar Barbosa
 
kotlin coroutine, What’s asynchronous programming What’s coroutine How Kotlin...
kotlin coroutine, What’s asynchronous programming What’s coroutine How Kotlin...kotlin coroutine, What’s asynchronous programming What’s coroutine How Kotlin...
kotlin coroutine, What’s asynchronous programming What’s coroutine How Kotlin...
Geng-Dian Huang
 
DO-178C OOT supplement: A user's perspective
DO-178C OOT supplement: A user's perspectiveDO-178C OOT supplement: A user's perspective
DO-178C OOT supplement: A user's perspective
AdaCore
 
Adding a BOLT pass
Adding a BOLT passAdding a BOLT pass
Adding a BOLT pass
Amir42407
 
Lecture11(Repetition-Part 2) computers.pdf
Lecture11(Repetition-Part 2) computers.pdfLecture11(Repetition-Part 2) computers.pdf
Lecture11(Repetition-Part 2) computers.pdf
jayyusimagdaong24
 
cscript_controller.pdf
cscript_controller.pdfcscript_controller.pdf
cscript_controller.pdf
VcTrn1
 
Quantum Computing Notes Ver1.0
Quantum Computing Notes Ver1.0Quantum Computing Notes Ver1.0
Quantum Computing Notes Ver1.0
Vijayananda Mohire
 
The State of Lightweight Threads for the JVM
The State of Lightweight Threads for the JVMThe State of Lightweight Threads for the JVM
The State of Lightweight Threads for the JVM
Volkan Yazıcı
 
Quantum Computing Notes Ver 1.2
Quantum Computing Notes Ver 1.2Quantum Computing Notes Ver 1.2
Quantum Computing Notes Ver 1.2
Vijayananda Mohire
 
Checking the Cross-Platform Framework Cocos2d-x
Checking the Cross-Platform Framework Cocos2d-xChecking the Cross-Platform Framework Cocos2d-x
Checking the Cross-Platform Framework Cocos2d-x
Andrey Karpov
 
c++ control structure statements .ppt
c++    control structure statements .pptc++    control structure statements .ppt
c++ control structure statements .ppt
zeenatparveen24
 
Kroening et al, v2c a verilog to c translator
Kroening et al, v2c   a verilog to c translatorKroening et al, v2c   a verilog to c translator
Kroening et al, v2c a verilog to c translator
sce,bhopal
 
Counter Wars (JEEConf 2016)
Counter Wars (JEEConf 2016)Counter Wars (JEEConf 2016)
Counter Wars (JEEConf 2016)
Alexey Fyodorov
 
The pocl Kernel Compiler
The pocl Kernel CompilerThe pocl Kernel Compiler
The pocl Kernel Compiler
Clay (Chih-Hao) Chang
 
1z0 808[1]
1z0 808[1]1z0 808[1]
1z0 808[1]
hildebrando vargas
 
ECET 365 Success Begins /newtonhelp.com 
ECET 365 Success Begins /newtonhelp.com ECET 365 Success Begins /newtonhelp.com 
ECET 365 Success Begins /newtonhelp.com 
myblue134
 
PVS-Studio. Static code analyzer. Windows/Linux, C/C++/C#. 2017
PVS-Studio. Static code analyzer. Windows/Linux, C/C++/C#. 2017PVS-Studio. Static code analyzer. Windows/Linux, C/C++/C#. 2017
PVS-Studio. Static code analyzer. Windows/Linux, C/C++/C#. 2017
Andrey Karpov
 
Full solution manual for modern processor design by john paul shen and mikko ...
Full solution manual for modern processor design by john paul shen and mikko ...Full solution manual for modern processor design by john paul shen and mikko ...
Full solution manual for modern processor design by john paul shen and mikko ...
neeraj7svp
 
Solution manual for modern processor design by john paul shen and mikko h. li...
Solution manual for modern processor design by john paul shen and mikko h. li...Solution manual for modern processor design by john paul shen and mikko h. li...
Solution manual for modern processor design by john paul shen and mikko h. li...
neeraj7svp
 
Multiple Choice Questions on JAVA (object oriented programming) bank 5 -- mem...
Multiple Choice Questions on JAVA (object oriented programming) bank 5 -- mem...Multiple Choice Questions on JAVA (object oriented programming) bank 5 -- mem...
Multiple Choice Questions on JAVA (object oriented programming) bank 5 -- mem...
Kuntal Bhowmick
 
Control Flow Analysis
Control Flow AnalysisControl Flow Analysis
Control Flow Analysis
Edgar Barbosa
 
kotlin coroutine, What’s asynchronous programming What’s coroutine How Kotlin...
kotlin coroutine, What’s asynchronous programming What’s coroutine How Kotlin...kotlin coroutine, What’s asynchronous programming What’s coroutine How Kotlin...
kotlin coroutine, What’s asynchronous programming What’s coroutine How Kotlin...
Geng-Dian Huang
 
DO-178C OOT supplement: A user's perspective
DO-178C OOT supplement: A user's perspectiveDO-178C OOT supplement: A user's perspective
DO-178C OOT supplement: A user's perspective
AdaCore
 
Adding a BOLT pass
Adding a BOLT passAdding a BOLT pass
Adding a BOLT pass
Amir42407
 
Lecture11(Repetition-Part 2) computers.pdf
Lecture11(Repetition-Part 2) computers.pdfLecture11(Repetition-Part 2) computers.pdf
Lecture11(Repetition-Part 2) computers.pdf
jayyusimagdaong24
 
cscript_controller.pdf
cscript_controller.pdfcscript_controller.pdf
cscript_controller.pdf
VcTrn1
 
Quantum Computing Notes Ver1.0
Quantum Computing Notes Ver1.0Quantum Computing Notes Ver1.0
Quantum Computing Notes Ver1.0
Vijayananda Mohire
 
The State of Lightweight Threads for the JVM
The State of Lightweight Threads for the JVMThe State of Lightweight Threads for the JVM
The State of Lightweight Threads for the JVM
Volkan Yazıcı
 
Quantum Computing Notes Ver 1.2
Quantum Computing Notes Ver 1.2Quantum Computing Notes Ver 1.2
Quantum Computing Notes Ver 1.2
Vijayananda Mohire
 
Checking the Cross-Platform Framework Cocos2d-x
Checking the Cross-Platform Framework Cocos2d-xChecking the Cross-Platform Framework Cocos2d-x
Checking the Cross-Platform Framework Cocos2d-x
Andrey Karpov
 
c++ control structure statements .ppt
c++    control structure statements .pptc++    control structure statements .ppt
c++ control structure statements .ppt
zeenatparveen24
 
Kroening et al, v2c a verilog to c translator
Kroening et al, v2c   a verilog to c translatorKroening et al, v2c   a verilog to c translator
Kroening et al, v2c a verilog to c translator
sce,bhopal
 
Counter Wars (JEEConf 2016)
Counter Wars (JEEConf 2016)Counter Wars (JEEConf 2016)
Counter Wars (JEEConf 2016)
Alexey Fyodorov
 
ECET 365 Success Begins /newtonhelp.com 
ECET 365 Success Begins /newtonhelp.com ECET 365 Success Begins /newtonhelp.com 
ECET 365 Success Begins /newtonhelp.com 
myblue134
 
PVS-Studio. Static code analyzer. Windows/Linux, C/C++/C#. 2017
PVS-Studio. Static code analyzer. Windows/Linux, C/C++/C#. 2017PVS-Studio. Static code analyzer. Windows/Linux, C/C++/C#. 2017
PVS-Studio. Static code analyzer. Windows/Linux, C/C++/C#. 2017
Andrey Karpov
 
Ad

More from Kuntal Bhowmick (20)

Hashing notes data structures (HASHING AND HASH FUNCTIONS)
Hashing notes data structures (HASHING AND HASH FUNCTIONS)Hashing notes data structures (HASHING AND HASH FUNCTIONS)
Hashing notes data structures (HASHING AND HASH FUNCTIONS)
Kuntal Bhowmick
 
1. introduction to E-commerce
1. introduction to E-commerce1. introduction to E-commerce
1. introduction to E-commerce
Kuntal Bhowmick
 
Computer graphics question for exam solved
Computer graphics question for exam solvedComputer graphics question for exam solved
Computer graphics question for exam solved
Kuntal Bhowmick
 
DBMS and Rdbms fundamental concepts
DBMS and Rdbms fundamental conceptsDBMS and Rdbms fundamental concepts
DBMS and Rdbms fundamental concepts
Kuntal Bhowmick
 
Java questions for interview
Java questions for interviewJava questions for interview
Java questions for interview
Kuntal Bhowmick
 
Java Interview Questions
Java Interview QuestionsJava Interview Questions
Java Interview Questions
Kuntal Bhowmick
 
Operating system Interview Questions
Operating system Interview QuestionsOperating system Interview Questions
Operating system Interview Questions
Kuntal Bhowmick
 
Computer Network Interview Questions
Computer Network Interview QuestionsComputer Network Interview Questions
Computer Network Interview Questions
Kuntal Bhowmick
 
C interview questions
C interview  questionsC interview  questions
C interview questions
Kuntal Bhowmick
 
C question
C questionC question
C question
Kuntal Bhowmick
 
Distributed operating systems cs704 a class test
Distributed operating systems cs704 a class testDistributed operating systems cs704 a class test
Distributed operating systems cs704 a class test
Kuntal Bhowmick
 
Cs291 assignment solution
Cs291 assignment solutionCs291 assignment solution
Cs291 assignment solution
Kuntal Bhowmick
 
CS291(C Programming) assignment
CS291(C Programming) assignmentCS291(C Programming) assignment
CS291(C Programming) assignment
Kuntal Bhowmick
 
C programming guide new
C programming guide newC programming guide new
C programming guide new
Kuntal Bhowmick
 
C lecture notes new
C lecture notes newC lecture notes new
C lecture notes new
Kuntal Bhowmick
 
Shell script assignment 3
Shell script assignment 3Shell script assignment 3
Shell script assignment 3
Kuntal Bhowmick
 
Basic shell programs assignment 1
Basic shell programs assignment 1Basic shell programs assignment 1
Basic shell programs assignment 1
Kuntal Bhowmick
 
Basic shell programs assignment 1_solution_manual
Basic shell programs assignment 1_solution_manualBasic shell programs assignment 1_solution_manual
Basic shell programs assignment 1_solution_manual
Kuntal Bhowmick
 
Shell programming assignment 2
Shell programming assignment 2Shell programming assignment 2
Shell programming assignment 2
Kuntal Bhowmick
 
Solution manual of shell programming assignment 2
Solution manual of shell programming assignment 2Solution manual of shell programming assignment 2
Solution manual of shell programming assignment 2
Kuntal Bhowmick
 
Hashing notes data structures (HASHING AND HASH FUNCTIONS)
Hashing notes data structures (HASHING AND HASH FUNCTIONS)Hashing notes data structures (HASHING AND HASH FUNCTIONS)
Hashing notes data structures (HASHING AND HASH FUNCTIONS)
Kuntal Bhowmick
 
1. introduction to E-commerce
1. introduction to E-commerce1. introduction to E-commerce
1. introduction to E-commerce
Kuntal Bhowmick
 
Computer graphics question for exam solved
Computer graphics question for exam solvedComputer graphics question for exam solved
Computer graphics question for exam solved
Kuntal Bhowmick
 
DBMS and Rdbms fundamental concepts
DBMS and Rdbms fundamental conceptsDBMS and Rdbms fundamental concepts
DBMS and Rdbms fundamental concepts
Kuntal Bhowmick
 
Java questions for interview
Java questions for interviewJava questions for interview
Java questions for interview
Kuntal Bhowmick
 
Java Interview Questions
Java Interview QuestionsJava Interview Questions
Java Interview Questions
Kuntal Bhowmick
 
Operating system Interview Questions
Operating system Interview QuestionsOperating system Interview Questions
Operating system Interview Questions
Kuntal Bhowmick
 
Computer Network Interview Questions
Computer Network Interview QuestionsComputer Network Interview Questions
Computer Network Interview Questions
Kuntal Bhowmick
 
Distributed operating systems cs704 a class test
Distributed operating systems cs704 a class testDistributed operating systems cs704 a class test
Distributed operating systems cs704 a class test
Kuntal Bhowmick
 
Cs291 assignment solution
Cs291 assignment solutionCs291 assignment solution
Cs291 assignment solution
Kuntal Bhowmick
 
CS291(C Programming) assignment
CS291(C Programming) assignmentCS291(C Programming) assignment
CS291(C Programming) assignment
Kuntal Bhowmick
 
Shell script assignment 3
Shell script assignment 3Shell script assignment 3
Shell script assignment 3
Kuntal Bhowmick
 
Basic shell programs assignment 1
Basic shell programs assignment 1Basic shell programs assignment 1
Basic shell programs assignment 1
Kuntal Bhowmick
 
Basic shell programs assignment 1_solution_manual
Basic shell programs assignment 1_solution_manualBasic shell programs assignment 1_solution_manual
Basic shell programs assignment 1_solution_manual
Kuntal Bhowmick
 
Shell programming assignment 2
Shell programming assignment 2Shell programming assignment 2
Shell programming assignment 2
Kuntal Bhowmick
 
Solution manual of shell programming assignment 2
Solution manual of shell programming assignment 2Solution manual of shell programming assignment 2
Solution manual of shell programming assignment 2
Kuntal Bhowmick
 
Ad

Recently uploaded (20)

Explainable-Artificial-Intelligence-in-Disaster-Risk-Management (2).pptx_2024...
Explainable-Artificial-Intelligence-in-Disaster-Risk-Management (2).pptx_2024...Explainable-Artificial-Intelligence-in-Disaster-Risk-Management (2).pptx_2024...
Explainable-Artificial-Intelligence-in-Disaster-Risk-Management (2).pptx_2024...
LiyaShaji4
 
Smart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptxSmart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptx
rushikeshnavghare94
 
aset and manufacturing optimization and connecting edge
aset and manufacturing optimization and connecting edgeaset and manufacturing optimization and connecting edge
aset and manufacturing optimization and connecting edge
alilamisse
 
Raish Khanji GTU 8th sem Internship Report.pdf
Raish Khanji GTU 8th sem Internship Report.pdfRaish Khanji GTU 8th sem Internship Report.pdf
Raish Khanji GTU 8th sem Internship Report.pdf
RaishKhanji
 
IntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdfIntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdf
Luiz Carneiro
 
Data Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptxData Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptx
RushaliDeshmukh2
 
Lecture 13 (Air and Noise Pollution and their Control) (1).pptx
Lecture 13 (Air and Noise Pollution and their Control) (1).pptxLecture 13 (Air and Noise Pollution and their Control) (1).pptx
Lecture 13 (Air and Noise Pollution and their Control) (1).pptx
huzaifabilalshams
 
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
inmishra17121973
 
Fourth Semester BE CSE BCS401 ADA Module 3 PPT.pptx
Fourth Semester BE CSE BCS401 ADA Module 3 PPT.pptxFourth Semester BE CSE BCS401 ADA Module 3 PPT.pptx
Fourth Semester BE CSE BCS401 ADA Module 3 PPT.pptx
VENKATESHBHAT25
 
ELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdfELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdf
Shiju Jacob
 
Mirada a 12 proyectos desarrollados con BIM.pdf
Mirada a 12 proyectos desarrollados con BIM.pdfMirada a 12 proyectos desarrollados con BIM.pdf
Mirada a 12 proyectos desarrollados con BIM.pdf
topitodosmasdos
 
introduction to machine learining for beginers
introduction to machine learining for beginersintroduction to machine learining for beginers
introduction to machine learining for beginers
JoydebSheet
 
Value Stream Mapping Worskshops for Intelligent Continuous Security
Value Stream Mapping Worskshops for Intelligent Continuous SecurityValue Stream Mapping Worskshops for Intelligent Continuous Security
Value Stream Mapping Worskshops for Intelligent Continuous Security
Marc Hornbeek
 
Artificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptxArtificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptx
aditichinar
 
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design ThinkingDT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DhruvChotaliya2
 
fluke dealers in bangalore..............
fluke dealers in bangalore..............fluke dealers in bangalore..............
fluke dealers in bangalore..............
Haresh Vaswani
 
vlsi digital circuits full power point presentation
vlsi digital circuits full power point presentationvlsi digital circuits full power point presentation
vlsi digital circuits full power point presentation
DrSunitaPatilUgaleKK
 
Smart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineeringSmart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineering
rushikeshnavghare94
 
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdfMAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
ssuser562df4
 
Gas Power Plant for Power Generation System
Gas Power Plant for Power Generation SystemGas Power Plant for Power Generation System
Gas Power Plant for Power Generation System
JourneyWithMe1
 
Explainable-Artificial-Intelligence-in-Disaster-Risk-Management (2).pptx_2024...
Explainable-Artificial-Intelligence-in-Disaster-Risk-Management (2).pptx_2024...Explainable-Artificial-Intelligence-in-Disaster-Risk-Management (2).pptx_2024...
Explainable-Artificial-Intelligence-in-Disaster-Risk-Management (2).pptx_2024...
LiyaShaji4
 
Smart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptxSmart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptx
rushikeshnavghare94
 
aset and manufacturing optimization and connecting edge
aset and manufacturing optimization and connecting edgeaset and manufacturing optimization and connecting edge
aset and manufacturing optimization and connecting edge
alilamisse
 
Raish Khanji GTU 8th sem Internship Report.pdf
Raish Khanji GTU 8th sem Internship Report.pdfRaish Khanji GTU 8th sem Internship Report.pdf
Raish Khanji GTU 8th sem Internship Report.pdf
RaishKhanji
 
IntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdfIntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdf
Luiz Carneiro
 
Data Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptxData Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptx
RushaliDeshmukh2
 
Lecture 13 (Air and Noise Pollution and their Control) (1).pptx
Lecture 13 (Air and Noise Pollution and their Control) (1).pptxLecture 13 (Air and Noise Pollution and their Control) (1).pptx
Lecture 13 (Air and Noise Pollution and their Control) (1).pptx
huzaifabilalshams
 
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
inmishra17121973
 
Fourth Semester BE CSE BCS401 ADA Module 3 PPT.pptx
Fourth Semester BE CSE BCS401 ADA Module 3 PPT.pptxFourth Semester BE CSE BCS401 ADA Module 3 PPT.pptx
Fourth Semester BE CSE BCS401 ADA Module 3 PPT.pptx
VENKATESHBHAT25
 
ELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdfELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdf
Shiju Jacob
 
Mirada a 12 proyectos desarrollados con BIM.pdf
Mirada a 12 proyectos desarrollados con BIM.pdfMirada a 12 proyectos desarrollados con BIM.pdf
Mirada a 12 proyectos desarrollados con BIM.pdf
topitodosmasdos
 
introduction to machine learining for beginers
introduction to machine learining for beginersintroduction to machine learining for beginers
introduction to machine learining for beginers
JoydebSheet
 
Value Stream Mapping Worskshops for Intelligent Continuous Security
Value Stream Mapping Worskshops for Intelligent Continuous SecurityValue Stream Mapping Worskshops for Intelligent Continuous Security
Value Stream Mapping Worskshops for Intelligent Continuous Security
Marc Hornbeek
 
Artificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptxArtificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptx
aditichinar
 
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design ThinkingDT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DhruvChotaliya2
 
fluke dealers in bangalore..............
fluke dealers in bangalore..............fluke dealers in bangalore..............
fluke dealers in bangalore..............
Haresh Vaswani
 
vlsi digital circuits full power point presentation
vlsi digital circuits full power point presentationvlsi digital circuits full power point presentation
vlsi digital circuits full power point presentation
DrSunitaPatilUgaleKK
 
Smart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineeringSmart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineering
rushikeshnavghare94
 
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdfMAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
ssuser562df4
 
Gas Power Plant for Power Generation System
Gas Power Plant for Power Generation SystemGas Power Plant for Power Generation System
Gas Power Plant for Power Generation System
JourneyWithMe1
 

Multiple Choice Questions on JAVA (object oriented programming) bank 4 -- loops

  • 1. MCQs BANK Page: 1 Object Oriented Programming Topic: Loops Instructions: This MCQs Bank contains question and solution on adjacent(even-odd) pages. First try to solve the MCQ by yourself, then look for the solution. Best viewed in “single page view” in PDF viewer. MCQs BANK No.: 4
  • 2. MCQs Bank on Object Oriented Programming Topic : Loops MCQ No: 1 Consider the following two statement: 1: The while statement is a looping construct that executes a block of code while a condition is true. 2: The loop condition must be a boolean expression. a) Both 1 and 2 are TRUE b) Only 1 is TRUE c) Both 1 and 2 are FALSE d) Only 2 is TRUE Page: 2
  • 3. MCQs Bank on Object Oriented Programming Topic : Loops MCQ No: 1 (Solution) Ans: a) Both 1 and 2 are TRUE Explanation: The while statement is a looping construct control statement that executes a block of code while a condition is true. You can either have a single statement or a block of code within the while loop. The loop will never be executed if the testing expression evaluates to false. The loop condition must be a boolean expression. Page: 3
  • 4. MCQs Bank on Object Oriented Programming Topic : Loops MCQ No: 2 In which loop the test is performed at the end and the loop body executes at least once? a) while loop b) for loop c) do-while loop d) all of these Page: 4
  • 5. MCQs Bank on Object Oriented Programming Topic : Loops MCQ No: 2 (Solution) Ans: c) do-while loop Explanation: The do-while loop is similar to the while loop, except that the test is performed at the end of the loop instead of at the beginning. This ensures that the loop will be executed at least once. A do-while loop begins with the keyword do, followed by the statements that make up the body of the loop. Page: 5
  • 6. MCQs Bank on Object Oriented Programming Topic : Loops MCQ No: 3 Which of the following loop use this looping construct (<initialization>; <loop condition>; <increment expression>) a) while loop b) for loop c) do-while loop d) all of the above Page: 6
  • 7. MCQs Bank on Object Oriented Programming Topic : Loops MCQ No: 3 (Solution) Ans: b) for loop Explanation: The for loop is a looping construct which can execute a set of instructions a specified number of times. It’s a counter controlled loop. The syntax of the loop is as follows: for (<initialization>; <loop condition>; <increment expression>) <loop body> Page: 7
  • 8. MCQs Bank on Object Oriented Programming Topic : Loops MCQ No: 4 What will be the output of the following program: a) Infinite Loop b) Hello c) Compiler Error d) Runtime Error Page: 8
  • 9. MCQs Bank on Object Oriented Programming Topic : Loops MCQ No: 4 (Solution) Ans: c) Compiler Error Explanation: The code gives Compiler Error. There is an error in condition check expression of for loop. Java differs from C++(or C) here. C++ considers all non-zero values as true and 0 as false. Unlike C++, an integer value expression cannot be placed where a boolean is expected in Java. Page: 9
  • 10. MCQs Bank on Object Oriented Programming Topic : Loops MCQ No: 5 What will be the output of the following code? // filename Test.java class Test { public static void main(String[] args) { for(int i = 0; true; i++) { System.out.println("Hello"); break; } } } a) Hello b) Infinite times Hello c) Compiler Error d) Runtime Error Page: 10
  • 11. MCQs Bank on Object Oriented Programming Topic : Loops MCQ No: 5 (Solution) Ans: a) Hello Explanation: The Program prints Hello 1 time only. This is because although the condition in the for loop is true(always true) but there is a break statement after the print statement, which terminates the loop and transfers the control outside the for loop. Page: 11
  • 12. MCQs Bank on Object Oriented Programming Topic : Loops MCQ No: 6 What will be the output of the following program: // filename Test.java class Test { public static void main(String[] args) { for(int i = 0; true; i++); { System.out.println("Hello"); break; } } } a) Executes but no output b) Prints Hello c) Runtime Error d) Compiler error: break outside switch or loop Page: 12
  • 13. MCQs Bank on Object Oriented Programming Topic : Loops MCQ No: 6 (Solution) Ans: d) Compiler error: break outside switch or loop Explanation: If you note carefully there is a semicolon just after the for loop. This makes the for loop as do nothing loop, because the for loop body is terminated at the semicolon. Now, break statement must be inside some loop block or switch- case block. As the break statement is not inside any loop body it generates error during compilation. Page: 13
  • 14. MCQs Bank on Object Oriented Programming Topic : Loops MCQ No: 7 What will be the Output of the following code? // filename Test.java class Test { public static void main(String[] args) { for(int i = 0; true; i++); { System.out.println("Hello"); //break; } } } a) Executes but print nothing b) Prints Hello c) Compiler Error:unreachable statement d) Runtime Error Page: 14
  • 15. MCQs Bank on Object Oriented Programming Topic : Loops MCQ No: 7 (Solution) Ans: c) Compiler Error: unreachable statement Explanation: In the for loop there is a semicolon at the end of loop, which makes the loop as do-nothing loop. Also the condition of the loop is always true which results in executing the blank statement infinite times. The flow of the program gets stuck at for loop statement and the print statement is never reached, as a result it give “unreachable statement” error. Page: 15
  • 16. MCQs Bank on Object Oriented Programming Topic : Loops MCQ No: 8 What will be the output of the following code? // filename Test.java class Test { public static void main(String[] args) { for(;;) { System.out.println("Hello"); break; } } } a) Hello b) Compiler Error c) Runtime Error d) Print Hello infinite times Page: 16
  • 17. MCQs Bank on Object Oriented Programming Topic : Loops MCQ No: 8 (Solution) Ans: a) Hello Explanation: All the sections in the for-loop header are optional. Any one of them can be left empty, but the two semicolons are mandatory. In particular, leaving out the <loop condition> signifies that the loop condition is true. The (;;) form of for loop is commonly used to construct an infinite loop. In the for loop body there is a break statement which terminates the for loop. Page: 17
  • 18. MCQs Bank on Object Oriented Programming Topic : Loops MCQ No: 9 A _____________ stops the iteration of a loop (while, do or for) and causes execution to resume at the top of the nearest enclosing loop. Fill in the blank. a) return statement b) break statement c) continue statement d) None of these Page: 18
  • 19. MCQs Bank on Object Oriented Programming Topic : Loops MCQ No: 9 (Solution) Ans: c) continue statement Explanation: A continue statement stops the iteration of a loop (while, do or for) and causes execution to resume at the top of the nearest enclosing loop. You use a continue statement when you do not want to execute the remaining statements in the loop, but you do not want to exit the loop itself. Page: 19
  • 20. MCQs Bank on Object Oriented Programming Topic : Loops MCQ No: 10 Which among the statements transfers the control of the program out of the enclosing loop ( for, while, do or switch statement).? a) return statement b) break statement c) continue statement d) None of these Page: 20
  • 21. MCQs Bank on Object Oriented Programming Topic : Loops MCQ No: 10 (Solution) Ans: b) break statement Explanation: The break statement transfers control out of the enclosing loop ( for, while, do or switch statement). You use a break statement when you want to jump immediately to the statement following the enclosing control structure. Page: 21