SlideShare a Scribd company logo
MCQs BANK
Page: 1
Object Oriented
Programming
Topic: Memory
Management
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.: 5
MCQs Bank on Object Oriented Programming
Topic : Memory Management
MCQ No: 1
_____________ is the process of
automatically freeing objects that
are no longer referenced by the
program. Fill in the blank.
a) Polymorphism
b) Data Hiding
c) Garbage collection
d) Encapsulation
Page: 2
MCQs Bank on Object Oriented Programming
Topic : Memory Management
MCQ No: 1 (Solution)
Ans: c) Garbage collection
Explanation: The Java virtual machine's
heap stores all objects created by a running
Java application. Objects are created by
the new keyword, but never freed explicitly
by the code. Garbage collection is the
process of automatically freeing objects
that are no longer referenced by the
program.
When an object is no longer referenced by
the program, the heap space it occupies
can be recycled so that the space is made
available for subsequent new objects. The
garbage collector must somehow determine
which objects are no longer referenced by
the program and make available the heap
space occupied by such unreferenced
objects.
Page: 3
MCQs Bank on Object Oriented Programming
Topic : Memory Management
MCQ No: 2
____________ occurs through the
course of normal program
execution, new objects are
allocated, and unreferenced
objects are freed such that free
portions of heap memory are left in
between portions occupied by live
objects. Fill in the blank.
a) Garbage Collection
b) Heap fragmentation
c) Encapsulation
d) Polymorphism
Page: 4
MCQs Bank on Object Oriented Programming
Topic : Memory Management
MCQ No: 2 (Solution)
Ans: b) Heap fragmentation
Explanation: Heap fragmentation
occurs through the course of normal
program execution. New objects are
allocated, and unreferenced objects are
freed such that free portions of heap
memory are left in between portions
occupied by live objects. Requests to
allocate new objects may have to be
filled by extending the size of the heap
even though there is enough total
unused space in the existing heap. This
will happen if there is not enough
contiguous free heap space available
into which the new object will fit.
Page: 5
MCQs Bank on Object Oriented Programming
Topic : Memory Management
MCQ No: 3
Which of the following are the
advantage of garbage collection?
a) Garbage collection relieves you
from the burden of freeing allocated
memory.
b) It can make you more productive.
c) It helps to ensure program
integrity.
d) All of the above.
Page: 6
MCQs Bank on Object Oriented Programming
Topic : Memory Management
MCQ No: 3 (Solution)
Ans: d) All of the above
Explanation: Garbage collection relieves
you from the burden of freeing allocated memory.
Knowing when to explicitly free allocated memory
can be very tricky. Giving this job to the Java
virtual machine has several advantages. First, it
can make you more productive. When
programming in non-garbage-collected
languages you can spend many late hours (or
days or weeks) chasing down an elusive memory
problem. When programming in Java you can
use that time more advantageously by getting
ahead of schedule or simply going home to have
a life. A second advantage of garbage collection
is that it helps ensure program integrity. Garbage
collection is an important part of Java's security
strategy. Java programmers are unable to
accidentally (or purposely) crash the Java virtual
machine by incorrectly freeing memory.
Page: 7
MCQs Bank on Object Oriented Programming
Topic : Memory Management
MCQ No: 4
What are the disadvantages of a
garbage-collection?
a) it adds an overhead that can
affect program performance.
b) it requires more CPU time
c) programmers have less control
on the memory management
d) all of the above
Page: 8
MCQs Bank on Object Oriented Programming
Topic : Memory Management
MCQ No: 4 (Solution)
Ans: d) all of the above
Explanation: A potential disadvantage
of a garbage-collection is that it adds an
overhead that can affect program
performance. The Java virtual machine
has to keep track of which objects are
being referenced by the executing
program, and finalize and free
unreferenced objects on the fly. This
activity will likely require more CPU time
than would have been required if the
program explicitly freed unnecessary
memory. In addition, programmers in a
garbage-collected environment have less
control over the scheduling of CPU time
devoted to freeing objects that are no
longer needed.
Page: 9
MCQs Bank on Object Oriented Programming
Topic : Memory Management
MCQ No: 5
Which method is called by the
garbage collector on an object
when garbage collection
determines that there are no more
references to the object?
a) finalize()
b) free()
c) delete()
d) deallocate()
Page: 10
MCQs Bank on Object Oriented Programming
Topic : Memory Management
MCQ No: 5 (Solution)
Ans: a) finalize()
Explanation: finalize() is called by the
garbage collector on an object when
garbage collection determines that
there are no more references to the
object. A subclass overrides the finalize
method to dispose of system resources
or to perform other cleanup.
The Finalize method is used to perform
cleanup operations on unmanaged
resources held by the current object
before the object is destroyed. The
method is protected and therefore is
accessible only through this class or
through a derived class.
Page: 11
MCQs Bank on Object Oriented Programming
Topic : Memory Management
MCQ No: 6
Which of the following keyword can
be used inside any method to refer
to the current object.
a) this
b) new
c) static
d) final
Page: 12
MCQs Bank on Object Oriented Programming
Topic : Memory Management
MCQ No: 6 (Solution)
Ans: a) this
Explanation:
Sometimes a method will need to
refer to the object that invoked it.
To allow this, Java defines the this
keyword. this can be used inside
any method to refer to the current
object.
That is, this is always a reference
to the object on which the method
was invoked. You can use this
anywhere a reference to an object
of the current class' type is
permitted.
Page: 13
MCQs Bank on Object Oriented Programming
Topic : Memory Management
MCQ No: 7
If we call a method passing a value,
it is known as call by value and the
changes being done in the called
method, is not affected in the calling
method. True or False?
a) True
b) False
Page: 14
MCQs Bank on Object Oriented Programming
Topic : Memory Management
MCQ No: 7 (Solution)
Ans: a) True
Explanation:
There is only call by value in java,
not call by reference(address). If we
call a method passing a value, it is
known as call by value. The
changes being done in the called
method, is not affected in the calling
method.
In case of call by value original
value is not changed.
Page: 15
MCQs Bank on Object Oriented Programming
Topic : Memory Management
MCQ No: 8
In case of _____________ original
value is changed if we made
changes in the called method, that
is if we pass object in place of any
primitive value, original value will be
changed. Fill in the blank.
a) call by value
b) call by reference
c) method overloading
d) method overriding
Page: 16
MCQs Bank on Object Oriented Programming
Topic : Memory Management
MCQ No: 8 (Solution)
Ans: b) call by reference
Explanation:
In case of call by reference original
value is changed if we made
changes in the called method.
If we pass object in place of any
primitive value, original value will be
changed.
Page: 17
MCQs Bank on Object Oriented Programming
Topic : Memory Management
MCQ No: 9
Which of the following modifier
keyword makes that the
programmer cannot change the
value anymore?
a) final
b) static
c) abstract
d) volatile
Page: 18
MCQs Bank on Object Oriented Programming
Topic : Memory Management
MCQ No: 9 (Solution)
Ans: a) final
Explanation: The final modifier keyword
makes that the programmer cannot change the
value anymore. The actual meaning depends on
whether it is applied to a class, a variable, or a
method.
final Classes:- A final class cannot have
subclasses. An example:
public final class MathConstants { ... }
This skeleton defines a class called
MathConstants that is publicly accessible but
cannot be subclassed.
Final Variables:-A final variable cannot be
changed once it is initialized.
volatile:-The value of an attribute is not cached
thread-locally, and is always read from the "main
memory"
abstract: -Can only be used in an abstract class,
can only be used on methods. The method does
not have a body, for example abstract void run();.
The body is provided by the subclass (inherited
from).
Page: 19
MCQs Bank on Object Oriented Programming
Topic : Memory Management
MCQ No: 10
A ____________ method cannot be
overridden by subclasses. Fill in the
blank.
a) public
b) default
c) final
d) volatile
Page: 20
MCQs Bank on Object Oriented Programming
Topic : Memory Management
MCQ No: 10 (Solution)
Ans: c) final
Explanation:
A final method cannot be overridden
by subclasses. There are two
reasons for introducing such a
method:
1. Disallowing subclasses to change
the meaning of the method;
2. Increasing efficiency by allowing
the compiler to turn calls to the
method into inline Java code.
Page: 21
MCQs Bank on Object Oriented Programming
Topic : Memory Management
MCQ No: 11
Can we OVERRIDE a static
method?
a) Yes
b) No
c) Unpredictable
d) Machine dependent
Page: 22
MCQs Bank on Object Oriented Programming
Topic : Memory Management
MCQ No: 11 (Solution)
Ans: b) No
Explanation:
No, we cannot override static
methods because method
overriding is based on dynamic
binding at runtime and the static
methods are bonded using static
binding at compile time. So, we
cannot override static methods.
Page: 23
MCQs Bank on Object Oriented Programming
Topic : Memory Management
MCQ No: 12
Can we OVERLOAD a static
method?
a) Yes
b) No
c) Unpredictable
d) Machine dependent
Page: 24
MCQs Bank on Object Oriented Programming
Topic : Memory Management
MCQ No: 12 (Solution)
Ans: a) Yes
Explanation:
The answer is Yes.
We can overload static methods. But
remember that the method signature
must be different.
Page: 25
MCQs Bank on Object Oriented Programming
Topic : Memory Management
MCQ No: 13
Can we overload the methods if
they are only different by static
keyword?
a) Yes
b) No
c) Unpredictable
d) Machine dependent
Page: 26
MCQs Bank on Object Oriented Programming
Topic : Memory Management
MCQ No: 13 (Solution)
Ans: b) No
Explanation:
The answer is No.
We cannot overload two methods if
they differ only by static keyword. It
give the error: method is already
defined in the class.
Page: 27
MCQs Bank on Object Oriented Programming
Topic : Memory Management
MCQ No: 14
A variable or method that is shared
by all instances of a class is called
a class variable or class method.
Such a variable or method in Java
is declared by the _____________
. Fill in the blank.
a) final Keyword
b) static keyword
c) volatile keyword
d) abstract keyword
Page: 28
MCQs Bank on Object Oriented Programming
Topic : Memory Management
MCQ No: 14 (Solution)
Ans: b) static keyword
Explanation:
A variable or method that is shared
by all instances of a class is called a
class variable or class method. You
recognize such a variable in Java by
the static keyword in the declaration.
A class variable will instantiate only
one copy of the variable for the
whole class instead of a separate
copy for each instance of a class. A
class variable belongs to a class, not
to an instance of the class.
Page: 29
MCQs Bank on Object Oriented Programming
Topic : Memory Management
MCQ No: 15
The Java programming language
allows you to define a class within
another class. Such a class is
called a __________. Fill in the
blank.
a) inside class
b) nested class
c) core class
d) static class
Page: 30
MCQs Bank on Object Oriented Programming
Topic : Memory Management
MCQ No: 15 (Solution)
Ans: b) nested class
Explanation: The Java programming
language allows you to define a class
within another class. Such a class is called
a nested class and is illustrated here:
class OuterClass {
...
class NestedClass {
... }
}
A nested class is a member of its enclosing
class. Non-static nested classes (inner
classes) have access to other members of
the enclosing class, even if they are
declared private. Static nested classes do
not have access to other members of the
enclosing class. As a member of the
OuterClass, a nested class can be
declared private, public, protected, or
package private.
Page: 31
MCQs Bank on Object Oriented Programming
Topic : Memory Management
MCQ No: 16
Which of the following are the
reasons of using nested classes?
a) It is a way of logically grouping
classes that are only used in one
place.
b) It increases encapsulation.
c) Nested classes can lead to more
readable and maintainable code.
d) All of these.
Page: 32
MCQs Bank on Object Oriented Programming
Topic : Memory Management
MCQ No: 16 (Solution)
Ans: d) All of these.
Explanation:
Logical grouping of classes— If a class is
useful to only one other class, then it is logical to
embed it in that class and keep the two together.
Nesting such "helper classes" makes their
package more streamlined.
Increased encapsulation— Consider two top-
level classes, A and B, where B needs access to
members of A that would otherwise be declared
private. By hiding class B within class A, A's
members can be declared private and B can
access them. In addition, B itself can be hidden
from the outside world.
More readable, maintainable code— Nesting
small classes within top-level classes places the
code closer to where it is used.
Page: 33
MCQs Bank on Object Oriented Programming
Topic : Memory Management
MCQ No: 17
If you declare an inner class(with a
class name) within the body of a
method. Such a class is known as
a ________________. Fill in the
blank.
a) anonymous inner class.
b) local inner class
c) global inner class.
d) static inner class
Page: 34
MCQs Bank on Object Oriented Programming
Topic : Memory Management
MCQ No: 17 (Solution)
Ans: b) local inner class
Explanation:
There are two additional types of
inner classes. You can declare an
inner class within the body of a
method. Such a class is known as a
local inner class. You can also
declare an inner class within the
body of a method without naming
it. These classes are known as
anonymous inner classes.
Page: 35
MCQs Bank on Object Oriented Programming
Topic : Memory Management
MCQ No: 18
You can also declare an inner
class within the body of a method
without naming it. Such class is
known as ________________. Fill
in the blank.
a) anonymous inner class.
b) local inner class.
c) global inner class.
d) static inner class
Page: 36
MCQs Bank on Object Oriented Programming
Topic : Memory Management
MCQ No: 18 (Solution)
Ans: a) anonymous inner class.
Explanation:
There are two additional types of
inner classes. You can declare an
inner class within the body of a
method. Such a class is known as a
local inner class. You can also
declare an inner class within the
body of a method without naming
it. These classes are known as
anonymous inner classes.
Page: 37
MCQs Bank on Object Oriented Programming
Topic : Memory Management
MCQ No: 19
You can use the access specifiers
— private, public, and protected —
to restrict access to inner classes.
True or False
a) True
b) False
Page: 38
MCQs Bank on Object Oriented Programming
Topic : Memory Management
MCQ No: 19 (Solution)
Ans: a) True
Explanation: You can use the same
modifiers for inner classes that you use
for other members of the outer class.
For example, you can use the access
specifiers — private, public, and
protected — to restrict access to inner
classes, just as you do to other class
members.
Page: 39
MCQs Bank on Object Oriented Programming
Topic : Memory Management
MCQ No: 20
Which of the following statements
are correct?
a) To instantiate an outer class,
you must first instantiate the inner
class.
b) To instantiate an inner class, you
must first instantiate the outer
class.
c) To instantiate an local inner
class, you must first instantiate the
local outer class.
d) To instantiate an anonymous
class, you must first instantiate the
local outer class.
Page: 40
MCQs Bank on Object Oriented Programming
Topic : Memory Management
MCQ No: 20 (Solution)
Ans: b) To instantiate an inner class,
you must first instantiate the outer
class.
Explanation:
To instantiate an inner class, you
must first instantiate the outer class.
Then, create the inner object within
the outer object with this syntax:
OuterClass.InnerClass innerObject =
outerObject.new InnerClass(); .
Page: 41

More Related Content

What's hot (19)

DOCX
Java mcq
avinash9821
 
DOCX
Mcs 024 assignment solution (2020-21)
smumbahelp
 
PDF
Concurrency on the JVM
Bernhard Huemer
 
PPS
Java session13
Niit Care
 
PDF
37 Java Interview Questions
Arc & Codementor
 
PDF
Class notes(week 9) on multithreading
Kuntal Bhowmick
 
PDF
MS.Net Interview Questions - Simplified
Mohd Manzoor Ahmed
 
PDF
Google lme4
Ben Bolker
 
PPTX
Clojure through the eyes of a Java Nut | [Mixed Nuts] at Pramati Technologies
Pramati Technologies
 
PPTX
Std 12 computer chapter 8 classes and objects in java important MCQs
Nuzhat Memon
 
PDF
Java reflection
Ranjith Chaz
 
PPTX
A (too) Short Introduction to Scala
Riccardo Cardin
 
DOCX
Design pattern application
gayatri thakur
 
PDF
Review of c_sharp2_features_part_ii
Nico Ludwig
 
PDF
My presentation at International Lisp Conference 2014 (ILC 2014): Hygienic Ma...
Tokyo Tech (Tokyo Institute of Technology)
 
PDF
Java/J2EE interview Qestions
Arun Vasanth
 
DOCX
C programming structures & union
Bathshebaparimala
 
PPS
Dacj 1-2 a
Niit Care
 
PDF
Exploring lambdas and invokedynamic for embedded systems
InfinIT - Innovationsnetværket for it
 
Java mcq
avinash9821
 
Mcs 024 assignment solution (2020-21)
smumbahelp
 
Concurrency on the JVM
Bernhard Huemer
 
Java session13
Niit Care
 
37 Java Interview Questions
Arc & Codementor
 
Class notes(week 9) on multithreading
Kuntal Bhowmick
 
MS.Net Interview Questions - Simplified
Mohd Manzoor Ahmed
 
Google lme4
Ben Bolker
 
Clojure through the eyes of a Java Nut | [Mixed Nuts] at Pramati Technologies
Pramati Technologies
 
Std 12 computer chapter 8 classes and objects in java important MCQs
Nuzhat Memon
 
Java reflection
Ranjith Chaz
 
A (too) Short Introduction to Scala
Riccardo Cardin
 
Design pattern application
gayatri thakur
 
Review of c_sharp2_features_part_ii
Nico Ludwig
 
My presentation at International Lisp Conference 2014 (ILC 2014): Hygienic Ma...
Tokyo Tech (Tokyo Institute of Technology)
 
Java/J2EE interview Qestions
Arun Vasanth
 
C programming structures & union
Bathshebaparimala
 
Dacj 1-2 a
Niit Care
 
Exploring lambdas and invokedynamic for embedded systems
InfinIT - Innovationsnetværket for it
 

Similar to Multiple Choice Questions on JAVA (object oriented programming) bank 5 -- memory management (20)

DOCX
25 java tough interview questions
Arun Banotra
 
PDF
50 common web developer interview questions [2020 updated] [www.full stack....
Alex Ershov
 
PDF
MicroManager_MATLAB_Implementation
Philip Mohun
 
DOCX
GSP 125 Entire Course NEW
shyamuopten
 
PDF
The Use of Development History in Software Refactoring Using a Multi-Objectiv...
Ali Ouni
 
PPT
Talking trash
michael.labriola
 
PPTX
2010 06-24 karlsruher entwicklertag
Marcel Bruch
 
PPTX
Software architacture recovery
Imdad Ul Haq
 
PDF
Garbage Collection in Java.pdf
SudhanshiBakre1
 
PDF
Full solution manual for modern processor design by john paul shen and mikko ...
neeraj7svp
 
PDF
Solution manual for modern processor design by john paul shen and mikko h. li...
neeraj7svp
 
PDF
Top 40 Javascript Interview Questions and Answers.pdf
paldibya712
 
PDF
Surge2012
davidapacheco
 
PPTX
OE Assignment - explains about assignment and dbms
cleopatraxer003
 
PDF
Oopp Lab Work
Heather Dionne
 
PDF
Performance Tuning - Memory leaks, Thread deadlocks, JDK tools
Haribabu Nandyal Padmanaban
 
PDF
Breaking Dependencies Legacy Code - Cork Software Crafters - September 2019
Paulo Clavijo
 
PDF
Java Programming
Tracy Clark
 
PDF
Devry CIS 247 Full Course Latest
Atifkhilji
 
PDF
BARRACUDA, AN OPEN SOURCE FRAMEWORK FOR PARALLELIZING DIVIDE AND CONQUER ALGO...
IJCI JOURNAL
 
25 java tough interview questions
Arun Banotra
 
50 common web developer interview questions [2020 updated] [www.full stack....
Alex Ershov
 
MicroManager_MATLAB_Implementation
Philip Mohun
 
GSP 125 Entire Course NEW
shyamuopten
 
The Use of Development History in Software Refactoring Using a Multi-Objectiv...
Ali Ouni
 
Talking trash
michael.labriola
 
2010 06-24 karlsruher entwicklertag
Marcel Bruch
 
Software architacture recovery
Imdad Ul Haq
 
Garbage Collection in Java.pdf
SudhanshiBakre1
 
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...
neeraj7svp
 
Top 40 Javascript Interview Questions and Answers.pdf
paldibya712
 
Surge2012
davidapacheco
 
OE Assignment - explains about assignment and dbms
cleopatraxer003
 
Oopp Lab Work
Heather Dionne
 
Performance Tuning - Memory leaks, Thread deadlocks, JDK tools
Haribabu Nandyal Padmanaban
 
Breaking Dependencies Legacy Code - Cork Software Crafters - September 2019
Paulo Clavijo
 
Java Programming
Tracy Clark
 
Devry CIS 247 Full Course Latest
Atifkhilji
 
BARRACUDA, AN OPEN SOURCE FRAMEWORK FOR PARALLELIZING DIVIDE AND CONQUER ALGO...
IJCI JOURNAL
 
Ad

More from Kuntal Bhowmick (20)

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
 
PDF
Solution manual of shell programming assignment 2
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
 
Solution manual of shell programming assignment 2
Kuntal Bhowmick
 
Ad

Recently uploaded (20)

PDF
Unified_Cloud_Comm_Presentation anil singh ppt
anilsingh298751
 
PPTX
Break Statement in Programming with 6 Real Examples
manojpoojary2004
 
PDF
MAD Unit - 1 Introduction of Android IT Department
JappanMavani
 
PDF
GTU Civil Engineering All Semester Syllabus.pdf
Vimal Bhojani
 
PPTX
MobileComputingMANET2023 MobileComputingMANET2023.pptx
masterfake98765
 
PPTX
Element 7. CHEMICAL AND BIOLOGICAL AGENT.pptx
merrandomohandas
 
PDF
monopile foundation seminar topic for civil engineering students
Ahina5
 
PDF
Book.pdf01_Intro.ppt algorithm for preperation stu used
archu26
 
PPTX
GitOps_Repo_Structure for begeinner(Scaffolindg)
DanialHabibi2
 
PDF
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
DOCX
8th International Conference on Electrical Engineering (ELEN 2025)
elelijjournal653
 
PDF
Pressure Measurement training for engineers and Technicians
AIESOLUTIONS
 
PPTX
Solar Thermal Energy System Seminar.pptx
Gpc Purapuza
 
PPTX
The Role of Information Technology in Environmental Protectio....pptx
nallamillisriram
 
PPTX
Server Side Web Development Unit 1 of Nodejs.pptx
sneha852132
 
PPTX
Introduction to Neural Networks and Perceptron Learning Algorithm.pptx
Kayalvizhi A
 
DOCX
CS-802 (A) BDH Lab manual IPS Academy Indore
thegodhimself05
 
DOC
MRRS Strength and Durability of Concrete
CivilMythili
 
PPTX
Green Building & Energy Conservation ppt
Sagar Sarangi
 
PDF
Ethics and Trustworthy AI in Healthcare – Governing Sensitive Data, Profiling...
AlqualsaDIResearchGr
 
Unified_Cloud_Comm_Presentation anil singh ppt
anilsingh298751
 
Break Statement in Programming with 6 Real Examples
manojpoojary2004
 
MAD Unit - 1 Introduction of Android IT Department
JappanMavani
 
GTU Civil Engineering All Semester Syllabus.pdf
Vimal Bhojani
 
MobileComputingMANET2023 MobileComputingMANET2023.pptx
masterfake98765
 
Element 7. CHEMICAL AND BIOLOGICAL AGENT.pptx
merrandomohandas
 
monopile foundation seminar topic for civil engineering students
Ahina5
 
Book.pdf01_Intro.ppt algorithm for preperation stu used
archu26
 
GitOps_Repo_Structure for begeinner(Scaffolindg)
DanialHabibi2
 
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
8th International Conference on Electrical Engineering (ELEN 2025)
elelijjournal653
 
Pressure Measurement training for engineers and Technicians
AIESOLUTIONS
 
Solar Thermal Energy System Seminar.pptx
Gpc Purapuza
 
The Role of Information Technology in Environmental Protectio....pptx
nallamillisriram
 
Server Side Web Development Unit 1 of Nodejs.pptx
sneha852132
 
Introduction to Neural Networks and Perceptron Learning Algorithm.pptx
Kayalvizhi A
 
CS-802 (A) BDH Lab manual IPS Academy Indore
thegodhimself05
 
MRRS Strength and Durability of Concrete
CivilMythili
 
Green Building & Energy Conservation ppt
Sagar Sarangi
 
Ethics and Trustworthy AI in Healthcare – Governing Sensitive Data, Profiling...
AlqualsaDIResearchGr
 

Multiple Choice Questions on JAVA (object oriented programming) bank 5 -- memory management

  • 1. MCQs BANK Page: 1 Object Oriented Programming Topic: Memory Management 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.: 5
  • 2. MCQs Bank on Object Oriented Programming Topic : Memory Management MCQ No: 1 _____________ is the process of automatically freeing objects that are no longer referenced by the program. Fill in the blank. a) Polymorphism b) Data Hiding c) Garbage collection d) Encapsulation Page: 2
  • 3. MCQs Bank on Object Oriented Programming Topic : Memory Management MCQ No: 1 (Solution) Ans: c) Garbage collection Explanation: The Java virtual machine's heap stores all objects created by a running Java application. Objects are created by the new keyword, but never freed explicitly by the code. Garbage collection is the process of automatically freeing objects that are no longer referenced by the program. When an object is no longer referenced by the program, the heap space it occupies can be recycled so that the space is made available for subsequent new objects. The garbage collector must somehow determine which objects are no longer referenced by the program and make available the heap space occupied by such unreferenced objects. Page: 3
  • 4. MCQs Bank on Object Oriented Programming Topic : Memory Management MCQ No: 2 ____________ occurs through the course of normal program execution, new objects are allocated, and unreferenced objects are freed such that free portions of heap memory are left in between portions occupied by live objects. Fill in the blank. a) Garbage Collection b) Heap fragmentation c) Encapsulation d) Polymorphism Page: 4
  • 5. MCQs Bank on Object Oriented Programming Topic : Memory Management MCQ No: 2 (Solution) Ans: b) Heap fragmentation Explanation: Heap fragmentation occurs through the course of normal program execution. New objects are allocated, and unreferenced objects are freed such that free portions of heap memory are left in between portions occupied by live objects. Requests to allocate new objects may have to be filled by extending the size of the heap even though there is enough total unused space in the existing heap. This will happen if there is not enough contiguous free heap space available into which the new object will fit. Page: 5
  • 6. MCQs Bank on Object Oriented Programming Topic : Memory Management MCQ No: 3 Which of the following are the advantage of garbage collection? a) Garbage collection relieves you from the burden of freeing allocated memory. b) It can make you more productive. c) It helps to ensure program integrity. d) All of the above. Page: 6
  • 7. MCQs Bank on Object Oriented Programming Topic : Memory Management MCQ No: 3 (Solution) Ans: d) All of the above Explanation: Garbage collection relieves you from the burden of freeing allocated memory. Knowing when to explicitly free allocated memory can be very tricky. Giving this job to the Java virtual machine has several advantages. First, it can make you more productive. When programming in non-garbage-collected languages you can spend many late hours (or days or weeks) chasing down an elusive memory problem. When programming in Java you can use that time more advantageously by getting ahead of schedule or simply going home to have a life. A second advantage of garbage collection is that it helps ensure program integrity. Garbage collection is an important part of Java's security strategy. Java programmers are unable to accidentally (or purposely) crash the Java virtual machine by incorrectly freeing memory. Page: 7
  • 8. MCQs Bank on Object Oriented Programming Topic : Memory Management MCQ No: 4 What are the disadvantages of a garbage-collection? a) it adds an overhead that can affect program performance. b) it requires more CPU time c) programmers have less control on the memory management d) all of the above Page: 8
  • 9. MCQs Bank on Object Oriented Programming Topic : Memory Management MCQ No: 4 (Solution) Ans: d) all of the above Explanation: A potential disadvantage of a garbage-collection is that it adds an overhead that can affect program performance. The Java virtual machine has to keep track of which objects are being referenced by the executing program, and finalize and free unreferenced objects on the fly. This activity will likely require more CPU time than would have been required if the program explicitly freed unnecessary memory. In addition, programmers in a garbage-collected environment have less control over the scheduling of CPU time devoted to freeing objects that are no longer needed. Page: 9
  • 10. MCQs Bank on Object Oriented Programming Topic : Memory Management MCQ No: 5 Which method is called by the garbage collector on an object when garbage collection determines that there are no more references to the object? a) finalize() b) free() c) delete() d) deallocate() Page: 10
  • 11. MCQs Bank on Object Oriented Programming Topic : Memory Management MCQ No: 5 (Solution) Ans: a) finalize() Explanation: finalize() is called by the garbage collector on an object when garbage collection determines that there are no more references to the object. A subclass overrides the finalize method to dispose of system resources or to perform other cleanup. The Finalize method is used to perform cleanup operations on unmanaged resources held by the current object before the object is destroyed. The method is protected and therefore is accessible only through this class or through a derived class. Page: 11
  • 12. MCQs Bank on Object Oriented Programming Topic : Memory Management MCQ No: 6 Which of the following keyword can be used inside any method to refer to the current object. a) this b) new c) static d) final Page: 12
  • 13. MCQs Bank on Object Oriented Programming Topic : Memory Management MCQ No: 6 (Solution) Ans: a) this Explanation: Sometimes a method will need to refer to the object that invoked it. To allow this, Java defines the this keyword. this can be used inside any method to refer to the current object. That is, this is always a reference to the object on which the method was invoked. You can use this anywhere a reference to an object of the current class' type is permitted. Page: 13
  • 14. MCQs Bank on Object Oriented Programming Topic : Memory Management MCQ No: 7 If we call a method passing a value, it is known as call by value and the changes being done in the called method, is not affected in the calling method. True or False? a) True b) False Page: 14
  • 15. MCQs Bank on Object Oriented Programming Topic : Memory Management MCQ No: 7 (Solution) Ans: a) True Explanation: There is only call by value in java, not call by reference(address). If we call a method passing a value, it is known as call by value. The changes being done in the called method, is not affected in the calling method. In case of call by value original value is not changed. Page: 15
  • 16. MCQs Bank on Object Oriented Programming Topic : Memory Management MCQ No: 8 In case of _____________ original value is changed if we made changes in the called method, that is if we pass object in place of any primitive value, original value will be changed. Fill in the blank. a) call by value b) call by reference c) method overloading d) method overriding Page: 16
  • 17. MCQs Bank on Object Oriented Programming Topic : Memory Management MCQ No: 8 (Solution) Ans: b) call by reference Explanation: In case of call by reference original value is changed if we made changes in the called method. If we pass object in place of any primitive value, original value will be changed. Page: 17
  • 18. MCQs Bank on Object Oriented Programming Topic : Memory Management MCQ No: 9 Which of the following modifier keyword makes that the programmer cannot change the value anymore? a) final b) static c) abstract d) volatile Page: 18
  • 19. MCQs Bank on Object Oriented Programming Topic : Memory Management MCQ No: 9 (Solution) Ans: a) final Explanation: The final modifier keyword makes that the programmer cannot change the value anymore. The actual meaning depends on whether it is applied to a class, a variable, or a method. final Classes:- A final class cannot have subclasses. An example: public final class MathConstants { ... } This skeleton defines a class called MathConstants that is publicly accessible but cannot be subclassed. Final Variables:-A final variable cannot be changed once it is initialized. volatile:-The value of an attribute is not cached thread-locally, and is always read from the "main memory" abstract: -Can only be used in an abstract class, can only be used on methods. The method does not have a body, for example abstract void run();. The body is provided by the subclass (inherited from). Page: 19
  • 20. MCQs Bank on Object Oriented Programming Topic : Memory Management MCQ No: 10 A ____________ method cannot be overridden by subclasses. Fill in the blank. a) public b) default c) final d) volatile Page: 20
  • 21. MCQs Bank on Object Oriented Programming Topic : Memory Management MCQ No: 10 (Solution) Ans: c) final Explanation: A final method cannot be overridden by subclasses. There are two reasons for introducing such a method: 1. Disallowing subclasses to change the meaning of the method; 2. Increasing efficiency by allowing the compiler to turn calls to the method into inline Java code. Page: 21
  • 22. MCQs Bank on Object Oriented Programming Topic : Memory Management MCQ No: 11 Can we OVERRIDE a static method? a) Yes b) No c) Unpredictable d) Machine dependent Page: 22
  • 23. MCQs Bank on Object Oriented Programming Topic : Memory Management MCQ No: 11 (Solution) Ans: b) No Explanation: No, we cannot override static methods because method overriding is based on dynamic binding at runtime and the static methods are bonded using static binding at compile time. So, we cannot override static methods. Page: 23
  • 24. MCQs Bank on Object Oriented Programming Topic : Memory Management MCQ No: 12 Can we OVERLOAD a static method? a) Yes b) No c) Unpredictable d) Machine dependent Page: 24
  • 25. MCQs Bank on Object Oriented Programming Topic : Memory Management MCQ No: 12 (Solution) Ans: a) Yes Explanation: The answer is Yes. We can overload static methods. But remember that the method signature must be different. Page: 25
  • 26. MCQs Bank on Object Oriented Programming Topic : Memory Management MCQ No: 13 Can we overload the methods if they are only different by static keyword? a) Yes b) No c) Unpredictable d) Machine dependent Page: 26
  • 27. MCQs Bank on Object Oriented Programming Topic : Memory Management MCQ No: 13 (Solution) Ans: b) No Explanation: The answer is No. We cannot overload two methods if they differ only by static keyword. It give the error: method is already defined in the class. Page: 27
  • 28. MCQs Bank on Object Oriented Programming Topic : Memory Management MCQ No: 14 A variable or method that is shared by all instances of a class is called a class variable or class method. Such a variable or method in Java is declared by the _____________ . Fill in the blank. a) final Keyword b) static keyword c) volatile keyword d) abstract keyword Page: 28
  • 29. MCQs Bank on Object Oriented Programming Topic : Memory Management MCQ No: 14 (Solution) Ans: b) static keyword Explanation: A variable or method that is shared by all instances of a class is called a class variable or class method. You recognize such a variable in Java by the static keyword in the declaration. A class variable will instantiate only one copy of the variable for the whole class instead of a separate copy for each instance of a class. A class variable belongs to a class, not to an instance of the class. Page: 29
  • 30. MCQs Bank on Object Oriented Programming Topic : Memory Management MCQ No: 15 The Java programming language allows you to define a class within another class. Such a class is called a __________. Fill in the blank. a) inside class b) nested class c) core class d) static class Page: 30
  • 31. MCQs Bank on Object Oriented Programming Topic : Memory Management MCQ No: 15 (Solution) Ans: b) nested class Explanation: The Java programming language allows you to define a class within another class. Such a class is called a nested class and is illustrated here: class OuterClass { ... class NestedClass { ... } } A nested class is a member of its enclosing class. Non-static nested classes (inner classes) have access to other members of the enclosing class, even if they are declared private. Static nested classes do not have access to other members of the enclosing class. As a member of the OuterClass, a nested class can be declared private, public, protected, or package private. Page: 31
  • 32. MCQs Bank on Object Oriented Programming Topic : Memory Management MCQ No: 16 Which of the following are the reasons of using nested classes? a) It is a way of logically grouping classes that are only used in one place. b) It increases encapsulation. c) Nested classes can lead to more readable and maintainable code. d) All of these. Page: 32
  • 33. MCQs Bank on Object Oriented Programming Topic : Memory Management MCQ No: 16 (Solution) Ans: d) All of these. Explanation: Logical grouping of classes— If a class is useful to only one other class, then it is logical to embed it in that class and keep the two together. Nesting such "helper classes" makes their package more streamlined. Increased encapsulation— Consider two top- level classes, A and B, where B needs access to members of A that would otherwise be declared private. By hiding class B within class A, A's members can be declared private and B can access them. In addition, B itself can be hidden from the outside world. More readable, maintainable code— Nesting small classes within top-level classes places the code closer to where it is used. Page: 33
  • 34. MCQs Bank on Object Oriented Programming Topic : Memory Management MCQ No: 17 If you declare an inner class(with a class name) within the body of a method. Such a class is known as a ________________. Fill in the blank. a) anonymous inner class. b) local inner class c) global inner class. d) static inner class Page: 34
  • 35. MCQs Bank on Object Oriented Programming Topic : Memory Management MCQ No: 17 (Solution) Ans: b) local inner class Explanation: There are two additional types of inner classes. You can declare an inner class within the body of a method. Such a class is known as a local inner class. You can also declare an inner class within the body of a method without naming it. These classes are known as anonymous inner classes. Page: 35
  • 36. MCQs Bank on Object Oriented Programming Topic : Memory Management MCQ No: 18 You can also declare an inner class within the body of a method without naming it. Such class is known as ________________. Fill in the blank. a) anonymous inner class. b) local inner class. c) global inner class. d) static inner class Page: 36
  • 37. MCQs Bank on Object Oriented Programming Topic : Memory Management MCQ No: 18 (Solution) Ans: a) anonymous inner class. Explanation: There are two additional types of inner classes. You can declare an inner class within the body of a method. Such a class is known as a local inner class. You can also declare an inner class within the body of a method without naming it. These classes are known as anonymous inner classes. Page: 37
  • 38. MCQs Bank on Object Oriented Programming Topic : Memory Management MCQ No: 19 You can use the access specifiers — private, public, and protected — to restrict access to inner classes. True or False a) True b) False Page: 38
  • 39. MCQs Bank on Object Oriented Programming Topic : Memory Management MCQ No: 19 (Solution) Ans: a) True Explanation: You can use the same modifiers for inner classes that you use for other members of the outer class. For example, you can use the access specifiers — private, public, and protected — to restrict access to inner classes, just as you do to other class members. Page: 39
  • 40. MCQs Bank on Object Oriented Programming Topic : Memory Management MCQ No: 20 Which of the following statements are correct? a) To instantiate an outer class, you must first instantiate the inner class. b) To instantiate an inner class, you must first instantiate the outer class. c) To instantiate an local inner class, you must first instantiate the local outer class. d) To instantiate an anonymous class, you must first instantiate the local outer class. Page: 40
  • 41. MCQs Bank on Object Oriented Programming Topic : Memory Management MCQ No: 20 (Solution) Ans: b) To instantiate an inner class, you must first instantiate the outer class. Explanation: To instantiate an inner class, you must first instantiate the outer class. Then, create the inner object within the outer object with this syntax: OuterClass.InnerClass innerObject = outerObject.new InnerClass(); . Page: 41