SlideShare a Scribd company logo
1 of 41
Download to read offline
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

Mcs 024 assignment solution (2020-21)
Mcs 024 assignment solution (2020-21)Mcs 024 assignment solution (2020-21)
Mcs 024 assignment solution (2020-21)smumbahelp
 
Java session13
Java session13Java session13
Java session13Niit Care
 
37 Java Interview Questions
37 Java Interview Questions37 Java Interview Questions
37 Java Interview QuestionsArc & Codementor
 
Class notes(week 9) on multithreading
Class notes(week 9) on multithreadingClass notes(week 9) on multithreading
Class notes(week 9) on multithreadingKuntal Bhowmick
 
MS.Net Interview Questions - Simplified
MS.Net Interview Questions - SimplifiedMS.Net Interview Questions - Simplified
MS.Net Interview Questions - SimplifiedMohd Manzoor Ahmed
 
Clojure through the eyes of a Java Nut | [Mixed Nuts] at Pramati Technologies
Clojure through the eyes of a Java Nut | [Mixed Nuts] at Pramati TechnologiesClojure through the eyes of a Java Nut | [Mixed Nuts] at Pramati Technologies
Clojure through the eyes of a Java Nut | [Mixed Nuts] at Pramati TechnologiesPramati Technologies
 
Std 12 computer chapter 8 classes and objects in java important MCQs
Std 12 computer chapter 8 classes and objects in java important MCQsStd 12 computer chapter 8 classes and objects in java important MCQs
Std 12 computer chapter 8 classes and objects in java important MCQsNuzhat Memon
 
A (too) Short Introduction to Scala
A (too) Short Introduction to ScalaA (too) Short Introduction to Scala
A (too) Short Introduction to ScalaRiccardo Cardin
 
Design pattern application
Design pattern applicationDesign pattern application
Design pattern applicationgayatri thakur
 
Review of c_sharp2_features_part_ii
Review of c_sharp2_features_part_iiReview of c_sharp2_features_part_ii
Review of c_sharp2_features_part_iiNico Ludwig
 
My presentation at International Lisp Conference 2014 (ILC 2014): Hygienic Ma...
My presentation at International Lisp Conference 2014 (ILC 2014): Hygienic Ma...My presentation at International Lisp Conference 2014 (ILC 2014): Hygienic Ma...
My presentation at International Lisp Conference 2014 (ILC 2014): Hygienic Ma...Tokyo Tech (Tokyo Institute of Technology)
 
Java/J2EE interview Qestions
Java/J2EE interview QestionsJava/J2EE interview Qestions
Java/J2EE interview QestionsArun Vasanth
 
C programming structures & union
C programming structures & unionC programming structures & union
C programming structures & unionBathshebaparimala
 

What's hot (19)

Java mcq
Java mcqJava mcq
Java mcq
 
Mcs 024 assignment solution (2020-21)
Mcs 024 assignment solution (2020-21)Mcs 024 assignment solution (2020-21)
Mcs 024 assignment solution (2020-21)
 
Concurrency on the JVM
Concurrency on the JVMConcurrency on the JVM
Concurrency on the JVM
 
Java session13
Java session13Java session13
Java session13
 
37 Java Interview Questions
37 Java Interview Questions37 Java Interview Questions
37 Java Interview Questions
 
Class notes(week 9) on multithreading
Class notes(week 9) on multithreadingClass notes(week 9) on multithreading
Class notes(week 9) on multithreading
 
MS.Net Interview Questions - Simplified
MS.Net Interview Questions - SimplifiedMS.Net Interview Questions - Simplified
MS.Net Interview Questions - Simplified
 
Google lme4
Google lme4Google lme4
Google lme4
 
Clojure through the eyes of a Java Nut | [Mixed Nuts] at Pramati Technologies
Clojure through the eyes of a Java Nut | [Mixed Nuts] at Pramati TechnologiesClojure through the eyes of a Java Nut | [Mixed Nuts] at Pramati Technologies
Clojure through the eyes of a Java Nut | [Mixed Nuts] at Pramati Technologies
 
Std 12 computer chapter 8 classes and objects in java important MCQs
Std 12 computer chapter 8 classes and objects in java important MCQsStd 12 computer chapter 8 classes and objects in java important MCQs
Std 12 computer chapter 8 classes and objects in java important MCQs
 
Java reflection
Java reflectionJava reflection
Java reflection
 
A (too) Short Introduction to Scala
A (too) Short Introduction to ScalaA (too) Short Introduction to Scala
A (too) Short Introduction to Scala
 
Design pattern application
Design pattern applicationDesign pattern application
Design pattern application
 
Review of c_sharp2_features_part_ii
Review of c_sharp2_features_part_iiReview of c_sharp2_features_part_ii
Review of c_sharp2_features_part_ii
 
My presentation at International Lisp Conference 2014 (ILC 2014): Hygienic Ma...
My presentation at International Lisp Conference 2014 (ILC 2014): Hygienic Ma...My presentation at International Lisp Conference 2014 (ILC 2014): Hygienic Ma...
My presentation at International Lisp Conference 2014 (ILC 2014): Hygienic Ma...
 
Java/J2EE interview Qestions
Java/J2EE interview QestionsJava/J2EE interview Qestions
Java/J2EE interview Qestions
 
C programming structures & union
C programming structures & unionC programming structures & union
C programming structures & union
 
Dacj 1-2 a
Dacj 1-2 aDacj 1-2 a
Dacj 1-2 a
 
Exploring lambdas and invokedynamic for embedded systems
Exploring lambdas and invokedynamic for embedded systemsExploring lambdas and invokedynamic for embedded systems
Exploring lambdas and invokedynamic for embedded systems
 

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

25 java tough interview questions
25 java tough interview questions25 java tough interview questions
25 java tough interview questionsArun Banotra
 
50 common web developer interview questions [2020 updated] [www.full stack....
50 common web developer interview questions [2020 updated]   [www.full stack....50 common web developer interview questions [2020 updated]   [www.full stack....
50 common web developer interview questions [2020 updated] [www.full stack....Alex Ershov
 
MicroManager_MATLAB_Implementation
MicroManager_MATLAB_ImplementationMicroManager_MATLAB_Implementation
MicroManager_MATLAB_ImplementationPhilip Mohun
 
GSP 125 Entire Course NEW
GSP 125 Entire Course NEWGSP 125 Entire Course NEW
GSP 125 Entire Course NEWshyamuopten
 
The Use of Development History in Software Refactoring Using a Multi-Objectiv...
The Use of Development History in Software Refactoring Using a Multi-Objectiv...The Use of Development History in Software Refactoring Using a Multi-Objectiv...
The Use of Development History in Software Refactoring Using a Multi-Objectiv...Ali Ouni
 
2010 06-24 karlsruher entwicklertag
2010 06-24 karlsruher entwicklertag2010 06-24 karlsruher entwicklertag
2010 06-24 karlsruher entwicklertagMarcel Bruch
 
Software architacture recovery
Software architacture recoverySoftware architacture recovery
Software architacture recoveryImdad Ul Haq
 
Garbage Collection in Java.pdf
Garbage Collection in Java.pdfGarbage Collection in Java.pdf
Garbage Collection in Java.pdfSudhanshiBakre1
 
Solution manual for modern processor design by john paul shen and mikko h. li...
Solution manual for modern processor design by john paul shen and mikko h. li...Solution manual for modern processor design by john paul shen and mikko h. li...
Solution manual for modern processor design by john paul shen and mikko h. li...neeraj7svp
 
Full solution manual for modern processor design by john paul shen and mikko ...
Full solution manual for modern processor design by john paul shen and mikko ...Full solution manual for modern processor design by john paul shen and mikko ...
Full solution manual for modern processor design by john paul shen and mikko ...neeraj7svp
 
Performance Tuning - Memory leaks, Thread deadlocks, JDK tools
Performance Tuning -  Memory leaks, Thread deadlocks, JDK toolsPerformance Tuning -  Memory leaks, Thread deadlocks, JDK tools
Performance Tuning - Memory leaks, Thread deadlocks, JDK toolsHaribabu Nandyal Padmanaban
 
Breaking Dependencies Legacy Code - Cork Software Crafters - September 2019
Breaking Dependencies Legacy Code -  Cork Software Crafters - September 2019Breaking Dependencies Legacy Code -  Cork Software Crafters - September 2019
Breaking Dependencies Legacy Code - Cork Software Crafters - September 2019Paulo Clavijo
 
Java Programming
Java ProgrammingJava Programming
Java ProgrammingTracy Clark
 
Devry CIS 247 Full Course Latest
Devry CIS 247 Full Course LatestDevry CIS 247 Full Course Latest
Devry CIS 247 Full Course LatestAtifkhilji
 
BARRACUDA, AN OPEN SOURCE FRAMEWORK FOR PARALLELIZING DIVIDE AND CONQUER ALGO...
BARRACUDA, AN OPEN SOURCE FRAMEWORK FOR PARALLELIZING DIVIDE AND CONQUER ALGO...BARRACUDA, AN OPEN SOURCE FRAMEWORK FOR PARALLELIZING DIVIDE AND CONQUER ALGO...
BARRACUDA, AN OPEN SOURCE FRAMEWORK FOR PARALLELIZING DIVIDE AND CONQUER ALGO...IJCI JOURNAL
 
Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...
Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...
Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...NicheTech Com. Solutions Pvt. Ltd.
 
Software Profiling: Understanding Java Performance and how to profile in Java
Software Profiling: Understanding Java Performance and how to profile in JavaSoftware Profiling: Understanding Java Performance and how to profile in Java
Software Profiling: Understanding Java Performance and how to profile in JavaIsuru Perera
 

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

25 java tough interview questions
25 java tough interview questions25 java tough interview questions
25 java tough interview questions
 
50 common web developer interview questions [2020 updated] [www.full stack....
50 common web developer interview questions [2020 updated]   [www.full stack....50 common web developer interview questions [2020 updated]   [www.full stack....
50 common web developer interview questions [2020 updated] [www.full stack....
 
MicroManager_MATLAB_Implementation
MicroManager_MATLAB_ImplementationMicroManager_MATLAB_Implementation
MicroManager_MATLAB_Implementation
 
GSP 125 Entire Course NEW
GSP 125 Entire Course NEWGSP 125 Entire Course NEW
GSP 125 Entire Course NEW
 
The Use of Development History in Software Refactoring Using a Multi-Objectiv...
The Use of Development History in Software Refactoring Using a Multi-Objectiv...The Use of Development History in Software Refactoring Using a Multi-Objectiv...
The Use of Development History in Software Refactoring Using a Multi-Objectiv...
 
Talking trash
Talking trashTalking trash
Talking trash
 
2010 06-24 karlsruher entwicklertag
2010 06-24 karlsruher entwicklertag2010 06-24 karlsruher entwicklertag
2010 06-24 karlsruher entwicklertag
 
Software architacture recovery
Software architacture recoverySoftware architacture recovery
Software architacture recovery
 
Garbage Collection in Java.pdf
Garbage Collection in Java.pdfGarbage Collection in Java.pdf
Garbage Collection in Java.pdf
 
Solution manual for modern processor design by john paul shen and mikko h. li...
Solution manual for modern processor design by john paul shen and mikko h. li...Solution manual for modern processor design by john paul shen and mikko h. li...
Solution manual for modern processor design by john paul shen and mikko h. li...
 
Full solution manual for modern processor design by john paul shen and mikko ...
Full solution manual for modern processor design by john paul shen and mikko ...Full solution manual for modern processor design by john paul shen and mikko ...
Full solution manual for modern processor design by john paul shen and mikko ...
 
Surge2012
Surge2012Surge2012
Surge2012
 
Oopp Lab Work
Oopp Lab WorkOopp Lab Work
Oopp Lab Work
 
Performance Tuning - Memory leaks, Thread deadlocks, JDK tools
Performance Tuning -  Memory leaks, Thread deadlocks, JDK toolsPerformance Tuning -  Memory leaks, Thread deadlocks, JDK tools
Performance Tuning - Memory leaks, Thread deadlocks, JDK tools
 
Breaking Dependencies Legacy Code - Cork Software Crafters - September 2019
Breaking Dependencies Legacy Code -  Cork Software Crafters - September 2019Breaking Dependencies Legacy Code -  Cork Software Crafters - September 2019
Breaking Dependencies Legacy Code - Cork Software Crafters - September 2019
 
Java Programming
Java ProgrammingJava Programming
Java Programming
 
Devry CIS 247 Full Course Latest
Devry CIS 247 Full Course LatestDevry CIS 247 Full Course Latest
Devry CIS 247 Full Course Latest
 
BARRACUDA, AN OPEN SOURCE FRAMEWORK FOR PARALLELIZING DIVIDE AND CONQUER ALGO...
BARRACUDA, AN OPEN SOURCE FRAMEWORK FOR PARALLELIZING DIVIDE AND CONQUER ALGO...BARRACUDA, AN OPEN SOURCE FRAMEWORK FOR PARALLELIZING DIVIDE AND CONQUER ALGO...
BARRACUDA, AN OPEN SOURCE FRAMEWORK FOR PARALLELIZING DIVIDE AND CONQUER ALGO...
 
Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...
Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...
Objective of c in IOS , iOS Live Project Training Ahmedabad, MCA Live Project...
 
Software Profiling: Understanding Java Performance and how to profile in Java
Software Profiling: Understanding Java Performance and how to profile in JavaSoftware Profiling: Understanding Java Performance and how to profile in Java
Software Profiling: Understanding Java Performance and how to profile in Java
 

More from Kuntal Bhowmick

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

More from Kuntal Bhowmick (20)

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

Recently uploaded

Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvLewisJB
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
DATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage exampleDATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage examplePragyanshuParadkar1
 
pipeline in computer architecture design
pipeline in computer architecture  designpipeline in computer architecture  design
pipeline in computer architecture designssuser87fa0c1
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)Dr SOUNDIRARAJ N
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
Effects of rheological properties on mixing
Effects of rheological properties on mixingEffects of rheological properties on mixing
Effects of rheological properties on mixingviprabot1
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHC Sai Kiran
 

Recently uploaded (20)

Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvv
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
DATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage exampleDATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage example
 
pipeline in computer architecture design
pipeline in computer architecture  designpipeline in computer architecture  design
pipeline in computer architecture design
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
Effects of rheological properties on mixing
Effects of rheological properties on mixingEffects of rheological properties on mixing
Effects of rheological properties on mixing
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECH
 

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