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)

PPTX
REST in Peace
Kate Marshalkina
 
PPSX
Spring - Part 1 - IoC, Di and Beans
Hitesh-Java
 
PPTX
Packages,static,this keyword in java
Vishnu Suresh
 
PPTX
Java Server Pages
Kasun Madusanke
 
PPSX
OOP with Java - Continued
Hitesh-Java
 
PDF
Collections in Java Notes
Shalabh Chaudhary
 
PDF
Crud tutorial en
forkgrown
 
PPT
JavaScript
Sunil OS
 
PPTX
Constructor in java
Hitesh Kumar
 
PPTX
Ajax
Tech_MX
 
PPTX
Inheritance In Java
Manish Sahu
 
PPTX
Cookie & Session In ASP.NET
ShingalaKrupa
 
PPT
Java Servlets
BG Java EE Course
 
PPT
Jsp/Servlet
Sunil OS
 
PDF
Method, Constructor, Method Overloading, Method Overriding, Inheritance In Java
Jamsher bhanbhro
 
PPT
Packages and interfaces
vanithaRamasamy
 
PPTX
OOPS In JAVA.pptx
Sachin33417
 
PDF
Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...
Edureka!
 
PPT
Xml parsers
Manav Prasad
 
REST in Peace
Kate Marshalkina
 
Spring - Part 1 - IoC, Di and Beans
Hitesh-Java
 
Packages,static,this keyword in java
Vishnu Suresh
 
Java Server Pages
Kasun Madusanke
 
OOP with Java - Continued
Hitesh-Java
 
Collections in Java Notes
Shalabh Chaudhary
 
Crud tutorial en
forkgrown
 
JavaScript
Sunil OS
 
Constructor in java
Hitesh Kumar
 
Ajax
Tech_MX
 
Inheritance In Java
Manish Sahu
 
Cookie & Session In ASP.NET
ShingalaKrupa
 
Java Servlets
BG Java EE Course
 
Jsp/Servlet
Sunil OS
 
Method, Constructor, Method Overloading, Method Overriding, Inheritance In Java
Jamsher bhanbhro
 
Packages and interfaces
vanithaRamasamy
 
OOPS In JAVA.pptx
Sachin33417
 
Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...
Edureka!
 
Xml parsers
Manav Prasad
 

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 1 -- 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 1 -- 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
Multiple Choice Questions on JAVA (object oriented programming) bank 4 -- loops
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
 
Multiple Choice Questions on JAVA (object oriented programming) bank 5 -- mem...
Kuntal Bhowmick
 
Multiple Choice Questions on JAVA (object oriented programming) bank 4 -- loops
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
 
Ad

Recently uploaded (20)

PDF
Water Design_Manual_2005. KENYA FOR WASTER SUPPLY AND SEWERAGE
DancanNgutuku
 
PPTX
Heart Bleed Bug - A case study (Course: Cryptography and Network Security)
Adri Jovin
 
PDF
6th International Conference on Machine Learning Techniques and Data Science ...
ijistjournal
 
PDF
Statistical Data Analysis Using SPSS Software
shrikrishna kesharwani
 
PDF
Pressure Measurement training for engineers and Technicians
AIESOLUTIONS
 
DOCX
CS-802 (A) BDH Lab manual IPS Academy Indore
thegodhimself05
 
DOCX
8th International Conference on Electrical Engineering (ELEN 2025)
elelijjournal653
 
PPTX
EC3551-Transmission lines Demo class .pptx
Mahalakshmiprasannag
 
PPTX
265587293-NFPA 101 Life safety code-PPT-1.pptx
chandermwason
 
PPTX
Server Side Web Development Unit 1 of Nodejs.pptx
sneha852132
 
PPTX
The Role of Information Technology in Environmental Protectio....pptx
nallamillisriram
 
PPTX
Introduction to Neural Networks and Perceptron Learning Algorithm.pptx
Kayalvizhi A
 
PDF
PORTFOLIO Golam Kibria Khan — architect with a passion for thoughtful design...
MasumKhan59
 
PDF
MAD Unit - 2 Activity and Fragment Management in Android (Diploma IT)
JappanMavani
 
PDF
ARC--BUILDING-UTILITIES-2-PART-2 (1).pdf
IzzyBaniquedBusto
 
PPTX
Lecture 1 Shell and Tube Heat exchanger-1.pptx
mailforillegalwork
 
PDF
GTU Civil Engineering All Semester Syllabus.pdf
Vimal Bhojani
 
PPTX
Hashing Introduction , hash functions and techniques
sailajam21
 
PPTX
Green Building & Energy Conservation ppt
Sagar Sarangi
 
PPTX
Break Statement in Programming with 6 Real Examples
manojpoojary2004
 
Water Design_Manual_2005. KENYA FOR WASTER SUPPLY AND SEWERAGE
DancanNgutuku
 
Heart Bleed Bug - A case study (Course: Cryptography and Network Security)
Adri Jovin
 
6th International Conference on Machine Learning Techniques and Data Science ...
ijistjournal
 
Statistical Data Analysis Using SPSS Software
shrikrishna kesharwani
 
Pressure Measurement training for engineers and Technicians
AIESOLUTIONS
 
CS-802 (A) BDH Lab manual IPS Academy Indore
thegodhimself05
 
8th International Conference on Electrical Engineering (ELEN 2025)
elelijjournal653
 
EC3551-Transmission lines Demo class .pptx
Mahalakshmiprasannag
 
265587293-NFPA 101 Life safety code-PPT-1.pptx
chandermwason
 
Server Side Web Development Unit 1 of Nodejs.pptx
sneha852132
 
The Role of Information Technology in Environmental Protectio....pptx
nallamillisriram
 
Introduction to Neural Networks and Perceptron Learning Algorithm.pptx
Kayalvizhi A
 
PORTFOLIO Golam Kibria Khan — architect with a passion for thoughtful design...
MasumKhan59
 
MAD Unit - 2 Activity and Fragment Management in Android (Diploma IT)
JappanMavani
 
ARC--BUILDING-UTILITIES-2-PART-2 (1).pdf
IzzyBaniquedBusto
 
Lecture 1 Shell and Tube Heat exchanger-1.pptx
mailforillegalwork
 
GTU Civil Engineering All Semester Syllabus.pdf
Vimal Bhojani
 
Hashing Introduction , hash functions and techniques
sailajam21
 
Green Building & Energy Conservation ppt
Sagar Sarangi
 
Break Statement in Programming with 6 Real Examples
manojpoojary2004
 

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