SlideShare a Scribd company logo
MCQs BANK
Page: 1
Object Oriented
Programming
Topic: Class,Objects,
Conditional Statements
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.: 3
MCQs Bank on Object Oriented Programming
Topic: Class,Objects,Conditional Statements
MCQ No: 1
A _______ is the blueprint from
which individual objects are
created. Fill in the blank.
a) class
b) object
c) instance
d) structure
Page: 2
MCQs Bank on Object Oriented Programming
Topic: Class,Objects,Conditional Statements
MCQ No: 1 (Solution)
Ans: a) class
Explanation:
A class is the blueprint from which
individual objects are created. In
object-oriented terms, we say that
the object you create is an
instance of the class of objects.
Page: 3
MCQs Bank on Object Oriented Programming
Topic: Class,Objects,Conditional Statements
MCQ No: 2
Fill in the following blanks:-
Member variables in a class—these are
called _________ .
Variables in a method or block of
code—these are called ___________ .
Variables in method declarations—
these are called __________.
a) parameters, fields, local variables
b) fields, local variables, parameters
c) local variables, parameters, fields
d) parameters, local variables, fields
Page: 4
MCQs Bank on Object Oriented Programming
Topic: Class,Objects,Conditional Statements
MCQ No: 2 (Solution)
Ans: b) fields, local variables,
parameters
Explanation:
Member variables in a class—
these are called fields.
Variables in a method or block of
code—these are called local
variables.
Variables in method declarations—
these are called parameters.
Page: 5
MCQs Bank on Object Oriented Programming
Topic: Class,Objects,Conditional Statements
MCQ No: 3
The ________ keyword is a Java
operator that creates the object. Fill
in the blank.
a) const
b) new
c) static
d) import
Page: 6
MCQs Bank on Object Oriented Programming
Topic: Class,Objects,Conditional Statements
MCQ No: 3 (Solution)
Ans: b) new
Explanation: The new keyword is a
Java operator that creates the
object. The new operator is followed
by a call to a constructor, which
initializes the new object. Example:
Bicycle bike1 = new Bicycle(); it
creates an object of the Bicycle
class.
The new operator instantiates a
class by allocating memory for a
new object and returning a
reference to that memory. The
new operator also invokes the
object constructor.
Page: 7
MCQs Bank on Object Oriented Programming
Topic: Class,Objects,Conditional Statements
MCQ No: 4
The phrase "instantiating a class"
means the same thing as
______________ . Fill in the blank.
a) "creating an class."
b) "declaring a reference."
c) "creating an object."
d) "rename an object."
Page: 8
MCQs Bank on Object Oriented Programming
Topic: Class,Objects,Conditional Statements
MCQ No: 4 (Solution)
Ans: c) "creating an object."
Explanation:
The phrase "instantiating a class"
means the same thing as "creating
an object." When you create an
object, you are creating an
"instance" of a class, therefore
"instantiating" a class.
If you declare a reference like this:
class ref; the value of "ref" will be
undetermined until an object is
actually created and assigned to it.
Simply declaring a reference variable
does not create an object.
Page: 9
MCQs Bank on Object Oriented Programming
Topic: Class,Objects,Conditional Statements
MCQ No: 5
A _________ can be recognized
easily, because its declaration
uses the same name as the class
and it has no return type. Fill in the
blank.
a) method
b) constructor
c) destructor
d) reference
Page: 10
MCQs Bank on Object Oriented Programming
Topic: Class,Objects,Conditional Statements
MCQ No: 5 (Solution)
Ans: b) constructor
Explanation: Consider the following
class:-
This class contains a single
constructor. You can recognize a
constructor because its declaration
uses the same name as the class
and it has no return type.
Page: 11
MCQs Bank on Object Oriented Programming
Topic: Class,Objects,Conditional Statements
MCQ No: 6
If a class has multiple constructors,
they must have different
signatures. True or False
a) True
b) False
Page: 12
MCQs Bank on Object Oriented Programming
Topic: Class,Objects,Conditional Statements
MCQ No: 6 (Solution)
Ans: a) True
Explanation:
If a class has multiple constructors,
they must have different signatures.
The Java compiler differentiates the
constructors based on the number
and the type of the arguments.
Page: 13
MCQs Bank on Object Oriented Programming
Topic: Class,Objects,Conditional Statements
MCQ No: 7
All classes have at least one
constructor. If a class does not
explicitly declare any, the Java
compiler automatically provides
a no-argument constructor, called
the default constructor. True or
False
a) True
b) False
Page: 14
MCQs Bank on Object Oriented Programming
Topic: Class,Objects,Conditional Statements
MCQ No: 7 (Solution)
Ans: a) True
Explanation:
All classes have at least one
constructor. If a class does not
explicitly declare any, the Java
compiler automatically provides
a no-argument constructor, called
the default constructor. This default
constructor calls the class parent's
no-argument constructor, or the
Object constructor if the class has
no other parent. If the parent has no
constructor (Object does have
one), the compiler will reject the
program.
Page: 15
MCQs Bank on Object Oriented Programming
Topic: Class,Objects,Conditional Statements
MCQ No: 8
The data type of the value returned
by the method,( or void if the
method does not return a value) is
called ________. Fill in the blank.
a) return type
b) method name
c) parameters list
d) method signature
Page: 16
MCQs Bank on Object Oriented Programming
Topic: Class,Objects,Conditional Statements
MCQ No: 8 (Solution)
Ans: a) return type
Explanation: The return type—the data
type of the value returned by the method,
or void if the method does not return a
value.
The parameter list in parenthesis—a
comma-delimited list of input parameters,
preceded by their data types, enclosed by
parentheses, (). If there are no
parameters, you must use empty
parentheses.
Two of the components of a method
declaration comprise the method
signature—the method's name and the
parameter types. Example:
calculateAnswer(double, int, double,
double)
Page: 17
MCQs Bank on Object Oriented Programming
Topic: Class,Objects,Conditional Statements
MCQ No: 9
Typically, a method has a unique
name within its class. However, a
method might have the same name
as other methods due to
_________ . Fill in the blank.
a) method overriding
b) method overloading
c) both (a) and (b)
d) lack of new method name
Page: 18
MCQs Bank on Object Oriented Programming
Topic: Class,Objects,Conditional Statements
MCQ No: 9 (Solution)
Ans: c) both (a) and (b)
Explanation: Typically, a method
has a unique name within its class.
However, a method might have the
same name as other methods
due to method overloading.
If a subclass provides the specific
implementation of the method that
has been declared by one of its
parent class, it is known as method
overriding.
Page: 19
MCQs Bank on Object Oriented Programming
Topic: Class,Objects,Conditional Statements
MCQ No: 10
The Java programming language
supports overloading methods, and
Java can distinguish between
methods with different
_____________ . Fill in the blank.
a) method return type
b) method names
c) method signatures
d) method body
Page: 20
MCQs Bank on Object Oriented Programming
Topic: Class,Objects,Conditional Statements
MCQ No: 10 (Solution)
Ans: c) method signatures
Explanation: The Java language
supports overloading methods, and Java
can distinguish between methods with
different method signatures. This means
that methods within a class can have the
same name if they have different
parameter lists. Overloaded methods are
differentiated by the number and the type
of the arguments passed into the method.
You cannot declare more than one method
with the same name and the same number
and type of arguments, because the
compiler cannot tell them apart. The
compiler does not consider return type
when differentiating methods, so you
cannot declare two methods with the same
signature even if they have a different
return type.
Page: 21
MCQs Bank on Object Oriented Programming
Topic: Class,Objects,Conditional Statements
MCQ No: 11
A _________ is a special method
that is used to initialize a newly
created object and is called just
after the memory is allocated for
the object. It can be used to
initialize the objects ,to required ,or
default values at the time of object
creation.
a) destructor
b) new
c) constructor
d) static
Page: 22
MCQs Bank on Object Oriented Programming
Topic: Class,Objects,Conditional Statements
MCQ No: 11 (Solution)
Ans: c) constructor
Explanation:
A constructor is a special method
that is used to initialize a newly
created object and is called just after
the memory is allocated for the
object. It can be used to initialize the
objects ,to required ,or default values
at the time of object creation. It is not
mandatory for the coder to write a
constructor for the class. If no user
defined constructor is provided for a
class, compiler initializes member
variables to its default values.
Page: 23
MCQs Bank on Object Oriented Programming
Topic: Class,Objects,Conditional Statements
MCQ No: 12
In order to create a Constructor
observe the following rules
1. It has the same name as the
class
2. It should not return a value not
even void
a) Both rules are TRUE
b) Only the rule 1 is TRUE
c) Only the rule 2 is TRUE
d) Both rules are FALSE
Page: 24
MCQs Bank on Object Oriented Programming
Topic: Class,Objects,Conditional Statements
MCQ No: 12 (Solution)
Ans: a) Both rules are TRUE
Explanation:
In order to create a Constructor
observe the following rules
1. It has the same name as the class
2. It should not return a value not
even void
If no user defined constructor is
provided for a class, compiler
initializes member variables to its
default values.
Page: 25
MCQs Bank on Object Oriented Programming
Topic: Class,Objects,Conditional Statements
MCQ No: 13
Constructor overloading is a
technique in Java in which a class
can have any number of
constructors that differ in
_____________. Fill in the blank.
a) return type
b) parameter lists
c) constructor body
d) constructor name
Page: 26
MCQs Bank on Object Oriented Programming
Topic: Class,Objects,Conditional Statements
MCQ No: 13 (Solution)
Ans: b) parameter lists
Explanation:
Constructor overloading is a
technique in Java in which a class
can have any number of constructors
that differ in parameter lists. The
compiler differentiates these
constructors by taking into account
the number of parameters in the list
and their type.
Examples of valid constructors for
class Account are
Account(int a);
Account (int a,int b);
Account (String a,int b);
Page: 27
MCQs Bank on Object Oriented Programming
Topic: Class,Objects,Conditional Statements
MCQ No: 14
Java allows you to control access
to classes, methods, and fields via
so-called __________. Fill in the
blank.
a) encapsulation
b) constructors
c) access specifiers
d) polymorphism
Page: 28
MCQs Bank on Object Oriented Programming
Topic: Class,Objects,Conditional Statements
MCQ No: 14 (Solution)
Ans: c) access specifiers
Explanation:
One of the techniques in object-oriented
programming is encapsulation. It
concerns the hiding of data in a class and
making this class available only through
methods. In this way the chance of
making accidental mistakes in changing
values is minimized. Java allows you to
control access to classes, methods, and
fields via so-called access specifiers.
Java offers four access specifiers, listed
below in decreasing accessibility:
• public
• protected
• default (no specifier)
• private
Page: 29
MCQs Bank on Object Oriented Programming
Topic: Class,Objects,Conditional Statements
MCQ No: 15
__________ classes, methods,
and fields can be accessed from
everywhere. Fill in the blank.
a) private
b) public
c) protected
d) default
Page: 30
MCQs Bank on Object Oriented Programming
Topic: Class,Objects,Conditional Statements
MCQ No: 15 (Solution)
Ans: b) public
Explanation: public classes, methods,
and fields can be accessed from
everywhere. The only constraint is that a
file with Java source code can only
contain one public class whose name
must also match with the filename. You
use public classes, methods, or fields only
if you explicitly want to offer access to
these entities and if this access cannot do
any harm.
If you do not set access to specific level,
then such a class, method, or field will be
accessible from inside the same package
to which the class, method, or field
belongs, but not from outside this
package.
Page: 31
MCQs Bank on Object Oriented Programming
Topic: Class,Objects,Conditional Statements
MCQ No: 16
___________ access level when it
is appropriate for a class's
subclasses to have access to the
method or field, but not for
unrelated classes. Fill in the blank.
a) default
b) protected
c) public
d) private
Page: 32
MCQs Bank on Object Oriented Programming
Topic: Class,Objects,Conditional Statements
MCQ No: 16 (Solution)
Ans: b) protected
Explanation:
protected methods and fields can
only be accessed within the same
class to which the methods and
fields belong, within its subclasses,
and within classes of the same
package, but not from anywhere
else. You use the protected access
level when it is appropriate for a
class's subclasses to have access to
the method or field, but not for
unrelated classes.
Page: 33
MCQs Bank on Object Oriented Programming
Topic: Class,Objects,Conditional Statements
MCQ No: 17
________ methods and fields can
only be accessed within the same
class to which the methods and
fields belong. Fill in the blank.
a) private
b) public
c) protected
d) default
Page: 34
MCQs Bank on Object Oriented Programming
Topic: Class,Objects,Conditional Statements
MCQ No: 17 (Solution)
Ans: a) private
Explanation:
private methods and fields can only
be accessed within the same class to
which the methods and fields belong.
private methods and fields are not
visible within subclasses and are not
inherited by subclasses. So, the
private access specifier is opposite to
the public access specifier. It is mostly
used for encapsulation: data are
hidden within the class and accessor
methods are provided.
Page: 35
MCQs Bank on Object Oriented Programming
Topic: Class,Objects,Conditional Statements
MCQ No: 18
The conditional expression of an if-
statement in java must be a
_______________ . Fill in the
blank.
a) Arithmetic expression
b) Boolean expression
c) Non- Zero value
d) Zero value
Page: 36
MCQs Bank on Object Oriented Programming
Topic: Class,Objects,Conditional Statements
MCQ No: 18 (Solution)
Ans: b) Boolean expression
Explanation:
The if statement executes a block of
code only if the specified expression
is true. If the value is false, then the
if block is skipped and execution
continues with the rest of the
program. Note that the conditional
expression must be a Boolean
expression, which must give TRUE
or FALSE value. Any other
value(Zero or Non-Zero value) will
give compilation error.
Page: 37
MCQs Bank on Object Oriented Programming
Topic: Class,Objects,Conditional Statements
MCQ No: 19
The switch statement code block in
Java includes a __________ label
to use in cases where there are no
matches are found. Fill in the
blank.
a) outer
b) default
c) inner
d) continue
Page: 38
MCQs Bank on Object Oriented Programming
Topic: Class,Objects,Conditional Statements
MCQ No: 19 (Solution)
Ans: b) default
Explanation:
The switch case statement, also
called a case statement is a multi-way
branch with several choices. A switch
is easier to implement than a series of
if/else statements. The default level is
used to execute statements when no
matches are found.
Page: 39
MCQs Bank on Object Oriented Programming
Topic: Class,Objects,Conditional Statements
MCQ No: 20
When executing a switch
statement, the program falls
through to the next case.
Therefore, if you want to exit in the
middle of the switch statement
code block, you must insert a
_______________ . Fill in the
blank.
a) case statement
b) default statement
c) break statement
d) continue statement
Page: 40
MCQs Bank on Object Oriented Programming
Topic: Class,Objects,Conditional Statements
MCQ No: 20 (Solution)
Ans: c) break statement
Explanation:
When executing a switch statement,
the program falls through to the next
case. Therefore, if you want to exit in
the middle of the switch statement
code block, you must insert a break
statement, which causes the
program to continue executing after
the current code block.
Page: 41

More Related Content

What's hot (20)

PPT
Lecture 1-intro-to-software-development
Zahid Hussain
 
PDF
Case Study Research in Software Engineering
alessio_ferrari
 
PDF
Machine Learning and its Applications
Dr Ganesh Iyer
 
PPTX
COCOMO Model in software project management
Syed Hassan Ali
 
PPTX
All You Need to Know About Java – Advantages and Disadvantages
carolynebert3007
 
PDF
Topic Modeling - NLP
Rupak Roy
 
PPTX
Introduction Node.js
Erik van Appeldoorn
 
PPS
Software design principles
Ritesh Singh
 
PPT
L11 array list
teach4uin
 
PPT
White box testing
Ganesh Wedpathak
 
PPTX
Autoboxing And Unboxing In Java
chathuranga kasun bamunusingha
 
PDF
Web Application Frameworks - Web Technologies (1019888BNR)
Beat Signer
 
PPTX
Word2Vec
mohammad javad hasani
 
PPTX
Java 102 intro to object-oriented programming in java - exercises
agorolabs
 
PPTX
Android application development ppt
Gautam Kumar
 
PDF
Introduction to Java Programming
Ravi Kant Sahu
 
PDF
Learn Java with Dr. Rifat Shahriyar
Abir Mohammad
 
PPTX
Entity Framework Core
Kiran Shahi
 
PDF
Introduction to Web Frameworks
Dr Sarika Jadhav
 
PPT
Object Oriented Concepts and Principles
deonpmeyer
 
Lecture 1-intro-to-software-development
Zahid Hussain
 
Case Study Research in Software Engineering
alessio_ferrari
 
Machine Learning and its Applications
Dr Ganesh Iyer
 
COCOMO Model in software project management
Syed Hassan Ali
 
All You Need to Know About Java – Advantages and Disadvantages
carolynebert3007
 
Topic Modeling - NLP
Rupak Roy
 
Introduction Node.js
Erik van Appeldoorn
 
Software design principles
Ritesh Singh
 
L11 array list
teach4uin
 
White box testing
Ganesh Wedpathak
 
Autoboxing And Unboxing In Java
chathuranga kasun bamunusingha
 
Web Application Frameworks - Web Technologies (1019888BNR)
Beat Signer
 
Java 102 intro to object-oriented programming in java - exercises
agorolabs
 
Android application development ppt
Gautam Kumar
 
Introduction to Java Programming
Ravi Kant Sahu
 
Learn Java with Dr. Rifat Shahriyar
Abir Mohammad
 
Entity Framework Core
Kiran Shahi
 
Introduction to Web Frameworks
Dr Sarika Jadhav
 
Object Oriented Concepts and Principles
deonpmeyer
 

Similar to Multiple Choice Questions on JAVA (object oriented programming) bank 3 -- class,objects,conditional statements (20)

PDF
Starting Out with C++ Early Objects 9th Edition Gaddis Test Bank
anpebinthi21
 
PDF
Multiple Choice Questions on JAVA (object oriented programming) bank 8 -- int...
Kuntal Bhowmick
 
PPTX
03 Java Language And OOP Part III
Hari Christian
 
PPTX
PPT Lecture-1.4.pptx
HimanshuPandey957216
 
PDF
OOPs theory about its concepts and properties.
ssuser1af273
 
PDF
FP 301 OOP FINAL PAPER
Syahriha Ruslan
 
PPTX
Object Oriented Programming using C++ / C Plus Plus QUIZ
RAKSHITDOGRA1
 
PDF
22316-2019-Summer-model-answer-paper.pdf
PradipShinde53
 
PPTX
Chap-2 Classes & Methods.pptx
chetanpatilcp783
 
PDF
EEE 3rd year oops cat 3 ans
Karthik Venkatachalam
 
DOCX
Mca2030 object oriented programming – c++
smumbahelp
 
PDF
Starting Out with Java From Control Structures through Data Structures 3rd Ed...
anpebinthi21
 
PDF
Question 1How many parameters does a default constructor haveAn.pdf
arccreation001
 
PPT
Object -oriented analysis and design.ppt
pierrerj05
 
PPTX
Oop in kotlin
Abdul Rahman Masri Attal
 
PPTX
C++ & Data Structure - Unit - first.pptx
KONGUNADU COLLEGE OF ENGINEERING AND TECHNOLOGY
 
PDF
OOM MCQ 2018
lochan100
 
PPTX
Java PPT OOPS prepared by Abhinav J.pptx
JainSaab2
 
PPTX
UNIT I OOP AND JAVA FUNDAMENTALS CONSTRUCTOR
mohanrajm63
 
Starting Out with C++ Early Objects 9th Edition Gaddis Test Bank
anpebinthi21
 
Multiple Choice Questions on JAVA (object oriented programming) bank 8 -- int...
Kuntal Bhowmick
 
03 Java Language And OOP Part III
Hari Christian
 
PPT Lecture-1.4.pptx
HimanshuPandey957216
 
OOPs theory about its concepts and properties.
ssuser1af273
 
FP 301 OOP FINAL PAPER
Syahriha Ruslan
 
Object Oriented Programming using C++ / C Plus Plus QUIZ
RAKSHITDOGRA1
 
22316-2019-Summer-model-answer-paper.pdf
PradipShinde53
 
Chap-2 Classes & Methods.pptx
chetanpatilcp783
 
EEE 3rd year oops cat 3 ans
Karthik Venkatachalam
 
Mca2030 object oriented programming – c++
smumbahelp
 
Starting Out with Java From Control Structures through Data Structures 3rd Ed...
anpebinthi21
 
Question 1How many parameters does a default constructor haveAn.pdf
arccreation001
 
Object -oriented analysis and design.ppt
pierrerj05
 
C++ & Data Structure - Unit - first.pptx
KONGUNADU COLLEGE OF ENGINEERING AND TECHNOLOGY
 
OOM MCQ 2018
lochan100
 
Java PPT OOPS prepared by Abhinav J.pptx
JainSaab2
 
UNIT I OOP AND JAVA FUNDAMENTALS CONSTRUCTOR
mohanrajm63
 
Ad

More from Kuntal Bhowmick (20)

PDF
Multiple Choice Questions on JAVA (object oriented programming) bank 5 -- mem...
Kuntal Bhowmick
 
PDF
Hashing notes data structures (HASHING AND HASH FUNCTIONS)
Kuntal Bhowmick
 
PPT
1. introduction to E-commerce
Kuntal Bhowmick
 
DOCX
Computer graphics question for exam solved
Kuntal Bhowmick
 
PDF
DBMS and Rdbms fundamental concepts
Kuntal Bhowmick
 
PDF
Java questions for interview
Kuntal Bhowmick
 
PDF
Java Interview Questions
Kuntal Bhowmick
 
PDF
Operating system Interview Questions
Kuntal Bhowmick
 
PDF
Computer Network Interview Questions
Kuntal Bhowmick
 
PDF
C interview questions
Kuntal Bhowmick
 
PDF
C question
Kuntal Bhowmick
 
PDF
Distributed operating systems cs704 a class test
Kuntal Bhowmick
 
DOCX
Cs291 assignment solution
Kuntal Bhowmick
 
DOCX
CS291(C Programming) assignment
Kuntal Bhowmick
 
PDF
C programming guide new
Kuntal Bhowmick
 
PDF
C lecture notes new
Kuntal Bhowmick
 
PDF
Shell script assignment 3
Kuntal Bhowmick
 
DOCX
Basic shell programs assignment 1
Kuntal Bhowmick
 
PDF
Basic shell programs assignment 1_solution_manual
Kuntal Bhowmick
 
DOCX
Shell programming assignment 2
Kuntal Bhowmick
 
Multiple Choice Questions on JAVA (object oriented programming) bank 5 -- mem...
Kuntal Bhowmick
 
Hashing notes data structures (HASHING AND HASH FUNCTIONS)
Kuntal Bhowmick
 
1. introduction to E-commerce
Kuntal Bhowmick
 
Computer graphics question for exam solved
Kuntal Bhowmick
 
DBMS and Rdbms fundamental concepts
Kuntal Bhowmick
 
Java questions for interview
Kuntal Bhowmick
 
Java Interview Questions
Kuntal Bhowmick
 
Operating system Interview Questions
Kuntal Bhowmick
 
Computer Network Interview Questions
Kuntal Bhowmick
 
C interview questions
Kuntal Bhowmick
 
C question
Kuntal Bhowmick
 
Distributed operating systems cs704 a class test
Kuntal Bhowmick
 
Cs291 assignment solution
Kuntal Bhowmick
 
CS291(C Programming) assignment
Kuntal Bhowmick
 
C programming guide new
Kuntal Bhowmick
 
C lecture notes new
Kuntal Bhowmick
 
Shell script assignment 3
Kuntal Bhowmick
 
Basic shell programs assignment 1
Kuntal Bhowmick
 
Basic shell programs assignment 1_solution_manual
Kuntal Bhowmick
 
Shell programming assignment 2
Kuntal Bhowmick
 
Ad

Recently uploaded (20)

PPTX
澳洲电子毕业证澳大利亚圣母大学水印成绩单UNDA学生证网上可查学历
Taqyea
 
PPTX
Solar Thermal Energy System Seminar.pptx
Gpc Purapuza
 
PPTX
GitOps_Without_K8s_Training_detailed git repository
DanialHabibi2
 
PPTX
What is Shot Peening | Shot Peening is a Surface Treatment Process
Vibra Finish
 
PPTX
2025 CGI Congres - Surviving agile v05.pptx
Derk-Jan de Grood
 
PPTX
Worm gear strength and wear calculation as per standard VB Bhandari Databook.
shahveer210504
 
PDF
Electrical Machines and Their Protection.pdf
Nabajyoti Banik
 
PPTX
Water Resources Engineering (CVE 728)--Slide 3.pptx
mohammedado3
 
PPTX
Introduction to Design of Machine Elements
PradeepKumarS27
 
PDF
Data structures notes for unit 2 in computer science.pdf
sshubhamsingh265
 
PPTX
fatigue in aircraft structures-221113192308-0ad6dc8c.pptx
aviatecofficial
 
PDF
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
PDF
MAD Unit - 1 Introduction of Android IT Department
JappanMavani
 
PDF
Reasons for the succes of MENARD PRESSUREMETER.pdf
majdiamz
 
PDF
Viol_Alessandro_Presentazione_prelaurea.pdf
dsecqyvhbowrzxshhf
 
PPTX
Water Resources Engineering (CVE 728)--Slide 4.pptx
mohammedado3
 
PDF
Biomechanics of Gait: Engineering Solutions for Rehabilitation (www.kiu.ac.ug)
publication11
 
PPTX
The Role of Information Technology in Environmental Protectio....pptx
nallamillisriram
 
PDF
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
DOC
MRRS Strength and Durability of Concrete
CivilMythili
 
澳洲电子毕业证澳大利亚圣母大学水印成绩单UNDA学生证网上可查学历
Taqyea
 
Solar Thermal Energy System Seminar.pptx
Gpc Purapuza
 
GitOps_Without_K8s_Training_detailed git repository
DanialHabibi2
 
What is Shot Peening | Shot Peening is a Surface Treatment Process
Vibra Finish
 
2025 CGI Congres - Surviving agile v05.pptx
Derk-Jan de Grood
 
Worm gear strength and wear calculation as per standard VB Bhandari Databook.
shahveer210504
 
Electrical Machines and Their Protection.pdf
Nabajyoti Banik
 
Water Resources Engineering (CVE 728)--Slide 3.pptx
mohammedado3
 
Introduction to Design of Machine Elements
PradeepKumarS27
 
Data structures notes for unit 2 in computer science.pdf
sshubhamsingh265
 
fatigue in aircraft structures-221113192308-0ad6dc8c.pptx
aviatecofficial
 
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
MAD Unit - 1 Introduction of Android IT Department
JappanMavani
 
Reasons for the succes of MENARD PRESSUREMETER.pdf
majdiamz
 
Viol_Alessandro_Presentazione_prelaurea.pdf
dsecqyvhbowrzxshhf
 
Water Resources Engineering (CVE 728)--Slide 4.pptx
mohammedado3
 
Biomechanics of Gait: Engineering Solutions for Rehabilitation (www.kiu.ac.ug)
publication11
 
The Role of Information Technology in Environmental Protectio....pptx
nallamillisriram
 
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
MRRS Strength and Durability of Concrete
CivilMythili
 

Multiple Choice Questions on JAVA (object oriented programming) bank 3 -- class,objects,conditional statements

  • 1. MCQs BANK Page: 1 Object Oriented Programming Topic: Class,Objects, Conditional Statements 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.: 3
  • 2. MCQs Bank on Object Oriented Programming Topic: Class,Objects,Conditional Statements MCQ No: 1 A _______ is the blueprint from which individual objects are created. Fill in the blank. a) class b) object c) instance d) structure Page: 2
  • 3. MCQs Bank on Object Oriented Programming Topic: Class,Objects,Conditional Statements MCQ No: 1 (Solution) Ans: a) class Explanation: A class is the blueprint from which individual objects are created. In object-oriented terms, we say that the object you create is an instance of the class of objects. Page: 3
  • 4. MCQs Bank on Object Oriented Programming Topic: Class,Objects,Conditional Statements MCQ No: 2 Fill in the following blanks:- Member variables in a class—these are called _________ . Variables in a method or block of code—these are called ___________ . Variables in method declarations— these are called __________. a) parameters, fields, local variables b) fields, local variables, parameters c) local variables, parameters, fields d) parameters, local variables, fields Page: 4
  • 5. MCQs Bank on Object Oriented Programming Topic: Class,Objects,Conditional Statements MCQ No: 2 (Solution) Ans: b) fields, local variables, parameters Explanation: Member variables in a class— these are called fields. Variables in a method or block of code—these are called local variables. Variables in method declarations— these are called parameters. Page: 5
  • 6. MCQs Bank on Object Oriented Programming Topic: Class,Objects,Conditional Statements MCQ No: 3 The ________ keyword is a Java operator that creates the object. Fill in the blank. a) const b) new c) static d) import Page: 6
  • 7. MCQs Bank on Object Oriented Programming Topic: Class,Objects,Conditional Statements MCQ No: 3 (Solution) Ans: b) new Explanation: The new keyword is a Java operator that creates the object. The new operator is followed by a call to a constructor, which initializes the new object. Example: Bicycle bike1 = new Bicycle(); it creates an object of the Bicycle class. The new operator instantiates a class by allocating memory for a new object and returning a reference to that memory. The new operator also invokes the object constructor. Page: 7
  • 8. MCQs Bank on Object Oriented Programming Topic: Class,Objects,Conditional Statements MCQ No: 4 The phrase "instantiating a class" means the same thing as ______________ . Fill in the blank. a) "creating an class." b) "declaring a reference." c) "creating an object." d) "rename an object." Page: 8
  • 9. MCQs Bank on Object Oriented Programming Topic: Class,Objects,Conditional Statements MCQ No: 4 (Solution) Ans: c) "creating an object." Explanation: The phrase "instantiating a class" means the same thing as "creating an object." When you create an object, you are creating an "instance" of a class, therefore "instantiating" a class. If you declare a reference like this: class ref; the value of "ref" will be undetermined until an object is actually created and assigned to it. Simply declaring a reference variable does not create an object. Page: 9
  • 10. MCQs Bank on Object Oriented Programming Topic: Class,Objects,Conditional Statements MCQ No: 5 A _________ can be recognized easily, because its declaration uses the same name as the class and it has no return type. Fill in the blank. a) method b) constructor c) destructor d) reference Page: 10
  • 11. MCQs Bank on Object Oriented Programming Topic: Class,Objects,Conditional Statements MCQ No: 5 (Solution) Ans: b) constructor Explanation: Consider the following class:- This class contains a single constructor. You can recognize a constructor because its declaration uses the same name as the class and it has no return type. Page: 11
  • 12. MCQs Bank on Object Oriented Programming Topic: Class,Objects,Conditional Statements MCQ No: 6 If a class has multiple constructors, they must have different signatures. True or False a) True b) False Page: 12
  • 13. MCQs Bank on Object Oriented Programming Topic: Class,Objects,Conditional Statements MCQ No: 6 (Solution) Ans: a) True Explanation: If a class has multiple constructors, they must have different signatures. The Java compiler differentiates the constructors based on the number and the type of the arguments. Page: 13
  • 14. MCQs Bank on Object Oriented Programming Topic: Class,Objects,Conditional Statements MCQ No: 7 All classes have at least one constructor. If a class does not explicitly declare any, the Java compiler automatically provides a no-argument constructor, called the default constructor. True or False a) True b) False Page: 14
  • 15. MCQs Bank on Object Oriented Programming Topic: Class,Objects,Conditional Statements MCQ No: 7 (Solution) Ans: a) True Explanation: All classes have at least one constructor. If a class does not explicitly declare any, the Java compiler automatically provides a no-argument constructor, called the default constructor. This default constructor calls the class parent's no-argument constructor, or the Object constructor if the class has no other parent. If the parent has no constructor (Object does have one), the compiler will reject the program. Page: 15
  • 16. MCQs Bank on Object Oriented Programming Topic: Class,Objects,Conditional Statements MCQ No: 8 The data type of the value returned by the method,( or void if the method does not return a value) is called ________. Fill in the blank. a) return type b) method name c) parameters list d) method signature Page: 16
  • 17. MCQs Bank on Object Oriented Programming Topic: Class,Objects,Conditional Statements MCQ No: 8 (Solution) Ans: a) return type Explanation: The return type—the data type of the value returned by the method, or void if the method does not return a value. The parameter list in parenthesis—a comma-delimited list of input parameters, preceded by their data types, enclosed by parentheses, (). If there are no parameters, you must use empty parentheses. Two of the components of a method declaration comprise the method signature—the method's name and the parameter types. Example: calculateAnswer(double, int, double, double) Page: 17
  • 18. MCQs Bank on Object Oriented Programming Topic: Class,Objects,Conditional Statements MCQ No: 9 Typically, a method has a unique name within its class. However, a method might have the same name as other methods due to _________ . Fill in the blank. a) method overriding b) method overloading c) both (a) and (b) d) lack of new method name Page: 18
  • 19. MCQs Bank on Object Oriented Programming Topic: Class,Objects,Conditional Statements MCQ No: 9 (Solution) Ans: c) both (a) and (b) Explanation: Typically, a method has a unique name within its class. However, a method might have the same name as other methods due to method overloading. If a subclass provides the specific implementation of the method that has been declared by one of its parent class, it is known as method overriding. Page: 19
  • 20. MCQs Bank on Object Oriented Programming Topic: Class,Objects,Conditional Statements MCQ No: 10 The Java programming language supports overloading methods, and Java can distinguish between methods with different _____________ . Fill in the blank. a) method return type b) method names c) method signatures d) method body Page: 20
  • 21. MCQs Bank on Object Oriented Programming Topic: Class,Objects,Conditional Statements MCQ No: 10 (Solution) Ans: c) method signatures Explanation: The Java language supports overloading methods, and Java can distinguish between methods with different method signatures. This means that methods within a class can have the same name if they have different parameter lists. Overloaded methods are differentiated by the number and the type of the arguments passed into the method. You cannot declare more than one method with the same name and the same number and type of arguments, because the compiler cannot tell them apart. The compiler does not consider return type when differentiating methods, so you cannot declare two methods with the same signature even if they have a different return type. Page: 21
  • 22. MCQs Bank on Object Oriented Programming Topic: Class,Objects,Conditional Statements MCQ No: 11 A _________ is a special method that is used to initialize a newly created object and is called just after the memory is allocated for the object. It can be used to initialize the objects ,to required ,or default values at the time of object creation. a) destructor b) new c) constructor d) static Page: 22
  • 23. MCQs Bank on Object Oriented Programming Topic: Class,Objects,Conditional Statements MCQ No: 11 (Solution) Ans: c) constructor Explanation: A constructor is a special method that is used to initialize a newly created object and is called just after the memory is allocated for the object. It can be used to initialize the objects ,to required ,or default values at the time of object creation. It is not mandatory for the coder to write a constructor for the class. If no user defined constructor is provided for a class, compiler initializes member variables to its default values. Page: 23
  • 24. MCQs Bank on Object Oriented Programming Topic: Class,Objects,Conditional Statements MCQ No: 12 In order to create a Constructor observe the following rules 1. It has the same name as the class 2. It should not return a value not even void a) Both rules are TRUE b) Only the rule 1 is TRUE c) Only the rule 2 is TRUE d) Both rules are FALSE Page: 24
  • 25. MCQs Bank on Object Oriented Programming Topic: Class,Objects,Conditional Statements MCQ No: 12 (Solution) Ans: a) Both rules are TRUE Explanation: In order to create a Constructor observe the following rules 1. It has the same name as the class 2. It should not return a value not even void If no user defined constructor is provided for a class, compiler initializes member variables to its default values. Page: 25
  • 26. MCQs Bank on Object Oriented Programming Topic: Class,Objects,Conditional Statements MCQ No: 13 Constructor overloading is a technique in Java in which a class can have any number of constructors that differ in _____________. Fill in the blank. a) return type b) parameter lists c) constructor body d) constructor name Page: 26
  • 27. MCQs Bank on Object Oriented Programming Topic: Class,Objects,Conditional Statements MCQ No: 13 (Solution) Ans: b) parameter lists Explanation: Constructor overloading is a technique in Java in which a class can have any number of constructors that differ in parameter lists. The compiler differentiates these constructors by taking into account the number of parameters in the list and their type. Examples of valid constructors for class Account are Account(int a); Account (int a,int b); Account (String a,int b); Page: 27
  • 28. MCQs Bank on Object Oriented Programming Topic: Class,Objects,Conditional Statements MCQ No: 14 Java allows you to control access to classes, methods, and fields via so-called __________. Fill in the blank. a) encapsulation b) constructors c) access specifiers d) polymorphism Page: 28
  • 29. MCQs Bank on Object Oriented Programming Topic: Class,Objects,Conditional Statements MCQ No: 14 (Solution) Ans: c) access specifiers Explanation: One of the techniques in object-oriented programming is encapsulation. It concerns the hiding of data in a class and making this class available only through methods. In this way the chance of making accidental mistakes in changing values is minimized. Java allows you to control access to classes, methods, and fields via so-called access specifiers. Java offers four access specifiers, listed below in decreasing accessibility: • public • protected • default (no specifier) • private Page: 29
  • 30. MCQs Bank on Object Oriented Programming Topic: Class,Objects,Conditional Statements MCQ No: 15 __________ classes, methods, and fields can be accessed from everywhere. Fill in the blank. a) private b) public c) protected d) default Page: 30
  • 31. MCQs Bank on Object Oriented Programming Topic: Class,Objects,Conditional Statements MCQ No: 15 (Solution) Ans: b) public Explanation: public classes, methods, and fields can be accessed from everywhere. The only constraint is that a file with Java source code can only contain one public class whose name must also match with the filename. You use public classes, methods, or fields only if you explicitly want to offer access to these entities and if this access cannot do any harm. If you do not set access to specific level, then such a class, method, or field will be accessible from inside the same package to which the class, method, or field belongs, but not from outside this package. Page: 31
  • 32. MCQs Bank on Object Oriented Programming Topic: Class,Objects,Conditional Statements MCQ No: 16 ___________ access level when it is appropriate for a class's subclasses to have access to the method or field, but not for unrelated classes. Fill in the blank. a) default b) protected c) public d) private Page: 32
  • 33. MCQs Bank on Object Oriented Programming Topic: Class,Objects,Conditional Statements MCQ No: 16 (Solution) Ans: b) protected Explanation: protected methods and fields can only be accessed within the same class to which the methods and fields belong, within its subclasses, and within classes of the same package, but not from anywhere else. You use the protected access level when it is appropriate for a class's subclasses to have access to the method or field, but not for unrelated classes. Page: 33
  • 34. MCQs Bank on Object Oriented Programming Topic: Class,Objects,Conditional Statements MCQ No: 17 ________ methods and fields can only be accessed within the same class to which the methods and fields belong. Fill in the blank. a) private b) public c) protected d) default Page: 34
  • 35. MCQs Bank on Object Oriented Programming Topic: Class,Objects,Conditional Statements MCQ No: 17 (Solution) Ans: a) private Explanation: private methods and fields can only be accessed within the same class to which the methods and fields belong. private methods and fields are not visible within subclasses and are not inherited by subclasses. So, the private access specifier is opposite to the public access specifier. It is mostly used for encapsulation: data are hidden within the class and accessor methods are provided. Page: 35
  • 36. MCQs Bank on Object Oriented Programming Topic: Class,Objects,Conditional Statements MCQ No: 18 The conditional expression of an if- statement in java must be a _______________ . Fill in the blank. a) Arithmetic expression b) Boolean expression c) Non- Zero value d) Zero value Page: 36
  • 37. MCQs Bank on Object Oriented Programming Topic: Class,Objects,Conditional Statements MCQ No: 18 (Solution) Ans: b) Boolean expression Explanation: The if statement executes a block of code only if the specified expression is true. If the value is false, then the if block is skipped and execution continues with the rest of the program. Note that the conditional expression must be a Boolean expression, which must give TRUE or FALSE value. Any other value(Zero or Non-Zero value) will give compilation error. Page: 37
  • 38. MCQs Bank on Object Oriented Programming Topic: Class,Objects,Conditional Statements MCQ No: 19 The switch statement code block in Java includes a __________ label to use in cases where there are no matches are found. Fill in the blank. a) outer b) default c) inner d) continue Page: 38
  • 39. MCQs Bank on Object Oriented Programming Topic: Class,Objects,Conditional Statements MCQ No: 19 (Solution) Ans: b) default Explanation: The switch case statement, also called a case statement is a multi-way branch with several choices. A switch is easier to implement than a series of if/else statements. The default level is used to execute statements when no matches are found. Page: 39
  • 40. MCQs Bank on Object Oriented Programming Topic: Class,Objects,Conditional Statements MCQ No: 20 When executing a switch statement, the program falls through to the next case. Therefore, if you want to exit in the middle of the switch statement code block, you must insert a _______________ . Fill in the blank. a) case statement b) default statement c) break statement d) continue statement Page: 40
  • 41. MCQs Bank on Object Oriented Programming Topic: Class,Objects,Conditional Statements MCQ No: 20 (Solution) Ans: c) break statement Explanation: When executing a switch statement, the program falls through to the next case. Therefore, if you want to exit in the middle of the switch statement code block, you must insert a break statement, which causes the program to continue executing after the current code block. Page: 41