SlideShare a Scribd company logo
MCQs BANK
Page: 1
Object Oriented
Programming
Topic: Abstract Classes
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.: 7
MCQs Bank on Object Oriented Programming
Topic : Abstract Classes
MCQ No: 1
When the keyword _______ appears
in a class definition, it means that
zero or more of it’s methods are
abstract.
a) abstract
b) default
c) static
d) public
Page: 2
MCQs Bank on Object Oriented Programming
Topic : Abstract Classes
MCQ No: 1 (Solution)
Ans: a) abstract
Explanation:
When the keyword abstract
appears in a class definition, it
means that zero or more of it’s
methods are abstract.
Abstract class is a restricted class
that cannot be used to create
objects (to access it, it must be
inherited from another class).
Abstract method can only be used
in an abstract class, and it does
not have a body. The body is
provided by the subclass (inherited
from).
Page: 3
MCQs Bank on Object Oriented Programming
Topic : Abstract Classes
MCQ No: 2
An _________ method has no
body. Fill in the blank.
a) static
b) abstract
c) private
d) public
Page: 4
MCQs Bank on Object Oriented Programming
Topic : Abstract Classes
MCQ No: 2 (Solution)
Ans: b) abstract
Explanation: An abstract method
has no body. Some of the
subclass has to override it and
provide the implementation.
Abstract methods are declaration
only and it will not have
implementation. It will not have a
method body. A Java class
containing an abstract class must
be declared as abstract class.
Page: 5
MCQs Bank on Object Oriented Programming
Topic : Abstract Classes
MCQ No: 3
Objects cannot be created out of
abstract class. True or False
a) True
b) False
Page: 6
MCQs Bank on Object Oriented Programming
Topic : Abstract Classes
MCQ No: 3 (Solution)
Ans: a) True
Explanation:
Objects cannot be created out of
abstract class. Abstract classes
basically provide a guideline for the
properties and methods of an
object.
Page: 7
MCQs Bank on Object Oriented Programming
Topic : Abstract Classes
MCQ No: 4
An abstract class, which declared
with the “abstract” keyword, cannot
be instantiated. True or False?
a) True
b) False
Page: 8
MCQs Bank on Object Oriented Programming
Topic : Abstract Classes
MCQ No: 4 (Solution)
Ans: a) True
Explanation:
An abstract class, which declared
with the “abstract” keyword, cannot
be instantiated. This is because in
abstract class the methods are
declared only without defining
them.
Abstract classes cannot be
instantiated, but they can be sub
classed.
Page: 9
MCQs Bank on Object Oriented Programming
Topic : Abstract Classes
MCQ No: 5
In order to use abstract classes,
they have to be ______________ .
Fill in the blank.
a) subclassed
b) sub-divided
c) overridden
d) overloaded
Page: 10
MCQs Bank on Object Oriented Programming
Topic : Abstract Classes
MCQ No: 5 (Solution)
Ans: a) subclassed
Explanation: In order to use
abstract classes, they have to be
subclassed. There are situations in
which you want to define a
superclass that declares the
structure of a given abstraction
without providing a complete
implementation of every method.
That is, sometimes you want to
create a superclass that only defines
generalized form that will be shared
by all of its subclasses, leaving it to
each subclass to fill in the details.
Page: 11
MCQs Bank on Object Oriented Programming
Topic : Abstract Classes
MCQ No: 6
___________ are those methods
that must be overridden by
subclasses because they have no
implementation specified in the
superclass. Fill in the blank.
a) default methods
b) abstract methods
c) static methods
d) hidden methods
Page: 12
MCQs Bank on Object Oriented Programming
Topic : Abstract Classes
MCQ No: 6 (Solution)
Ans: b) abstract methods
Explanation:
Consider a class Triangle. It has no
meaning if area( ) is not defined. In this
case, you want some way to ensure that
a subclass does, indeed, override all
necessary methods. Java’s solution to
this problem is the abstract method. You
can require that certain methods be
overridden by subclasses by specifying
the abstract type modifier.
These methods are sometimes referred
to as subclasser responsibility because
they have no implementation specified in
the superclass. Thus, a subclass must
override them—it cannot simply use the
version defined in the superclass.
Page: 13
MCQs Bank on Object Oriented Programming
Topic : Abstract Classes
MCQ No: 7
The correct way of declaring an
abstract method is
a) abstract return_type
method_name(parameter-list);
b) return_type
method_name(parameter-list)
abstract ;
c) return_type abstract
method_name(parameter-list);
d) all are correct
Page: 14
MCQs Bank on Object Oriented Programming
Topic : Abstract Classes
MCQ No: 7 (Solution)
Ans: a) abstract return_type
method_name(parameter-list);
Explanation:
The correct way of declaring an
abstract method is :
abstract return_type
method_name(parameter-list);
As you can see, no method body is
present. Any class that contains one
or more abstract methods must also
be declared abstract.
Page: 15
MCQs Bank on Object Oriented Programming
Topic : Abstract Classes
MCQ No: 8
There can be no objects of an
abstract class. True or False
a) True
b) False
Page: 16
MCQs Bank on Object Oriented Programming
Topic : Abstract Classes
MCQ No: 8 (Solution)
Ans: a) True
Explanation:
There can be no objects of an
abstract class. That is, an abstract
class cannot be directly instantiated
with the new operator. Such objects
would be useless, because an
abstract class is not fully defined.
Page: 17
MCQs Bank on Object Oriented Programming
Topic : Abstract Classes
MCQ No: 9
Can you declare abstract
constructors, or abstract static
methods ?
a) Yes
b) No
Page: 18
MCQs Bank on Object Oriented Programming
Topic : Abstract Classes
MCQ No: 9 (Solution)
Ans: b) No
Explanation: You cannot declare
abstract constructors, or abstract static
methods. Constructors are invoked
automatically when objects of a class
is created using new operator. As an
abstract class cannot be directly
instantiated with the new operator so
you cannot declare abstract
constructors. static methods are class
methods, that is shared by multiple
objects(instances of the class) of a
class, as an abstract class cannot be
directly instantiated so it is not possible
to declare abstract static methods.
Page: 19
MCQs Bank on Object Oriented Programming
Topic : Abstract Classes
MCQ No: 10
Any subclass of an abstract class
must either implement all of the
abstract methods in the superclass,
or be itself declared abstract. True or
False?
a) True
b) False
Page: 20
MCQs Bank on Object Oriented Programming
Topic : Abstract Classes
MCQ No: 10 (Solution)
Ans: a) True
Explanation:
Any subclass of an abstract class
must either implement all of the
abstract methods in the superclass,
or be itself declared abstract.
Page: 21
MCQs Bank on Object Oriented Programming
Topic : Abstract Classes
MCQ No: 11
Is it possible to create a reference
to an abstract class so that it can
be used to point to a subclass
object ?
a) Yes, Possible
b) No, Not Possible
Page: 22
MCQs Bank on Object Oriented Programming
Topic : Abstract Classes
MCQ No: 11 (Solution)
Ans: a) Yes, Possible
Explanation:
Although abstract classes cannot be
used to instantiate objects, they can
be used to create object references,
because Java’s approach to run-time
polymorphism is implemented
through the use of superclass
references. Thus, it must be possible
to create a reference to an abstract
class so that it can be used to point
to a subclass object. It is through
superclass reference variables that
overridden methods are resolved at
run time.
Page: 23
MCQs Bank on Object Oriented Programming
Topic : Abstract Classes
MCQ No: 12
Methods declared as final cannot
be overridden. True or False
a) True
b) False
Page: 24
MCQs Bank on Object Oriented Programming
Topic : Abstract Classes
MCQ No: 12 (Solution)
Ans: a) True
Explanation:
While method overriding is one of
Java’s most powerful features, there
will be times when you will want to
prevent it from occurring. To disallow
a method from being overridden,
specify final as a modifier at the start
of its declaration.
Methods declared as final cannot be
overridden. If you attempt to do so, a
compile-time error will result.
Page: 25
MCQs Bank on Object Oriented Programming
Topic : Abstract Classes
MCQ No: 13
How would you will prevent a class
from being inherited?
a) By making the class abstract
b) By adding a comment statement
"Don't Inherit"
c) Precede the class declaration
with final
d) Requesting others to not inherit
the class
Page: 26
MCQs Bank on Object Oriented Programming
Topic : Abstract Classes
MCQ No: 13 (Solution)
Ans: c) Precede the class
declaration with final
Explanation: Sometimes you will want
to prevent a class from being inherited. To
do this, precede the class declaration with
final.Declaring a class as final implicitly
declares all of its methods as final, too.
Here is an example of a final class:
final class A {
// ...
}
// The following class is illegal.
class B extends A { // ERROR! Can't
subclass A
// ...
}
Page: 27
MCQs Bank on Object Oriented Programming
Topic : Abstract Classes
MCQ No: 14
It is illegal to declare a class as
both abstract and final. Yes or No?
a) Yes, it is illegal
b) No, it is completely legal.
Page: 28
MCQs Bank on Object Oriented Programming
Topic : Abstract Classes
MCQ No: 14 (Solution)
Ans: a) Yes, it is illegal
Explanation:
It is illegal to declare a class as both
abstract and final since an abstract
class is incomplete by itself and
relies upon its subclasses to provide
complete implementations.
Page: 29

More Related Content

What's hot (20)

PDF
Collections In Java
Binoj T E
 
PDF
Java Collections Tutorials
Prof. Erwin Globio
 
PDF
Lecture4 big data technology foundations
hktripathy
 
PPTX
CS8651 IP Unit 3.pptx
Vigneshkumar Ponnusamy
 
PPT
Java collections concept
kumar gaurav
 
PPT
android activity
Deepa Rani
 
ODP
Patterns in Python
dn
 
PDF
Java ArrayList Tutorial | Edureka
Edureka!
 
PPT
Java Servlets
Nitin Pai
 
PDF
Java Multiple Choice Questions and Answers
Java Projects
 
PPT
Object-oriented concepts
BG Java EE Course
 
PPTX
Introduction to Node js
Akshay Mathur
 
PPT
Sqlite
Kumar
 
PPTX
android sqlite
Deepa Rani
 
PPT
Mvc architecture
Surbhi Panhalkar
 
PPSX
Introduction to java
Ajay Sharma
 
PPTX
Collections framework in java
yugandhar vadlamudi
 
PPT
android layouts
Deepa Rani
 
PPTX
PORTFOLIO BY USING HTML & CSS
Meghaj Mallick
 
PPTX
Memory Management & Garbage Collection
Abhishek Sur
 
Collections In Java
Binoj T E
 
Java Collections Tutorials
Prof. Erwin Globio
 
Lecture4 big data technology foundations
hktripathy
 
CS8651 IP Unit 3.pptx
Vigneshkumar Ponnusamy
 
Java collections concept
kumar gaurav
 
android activity
Deepa Rani
 
Patterns in Python
dn
 
Java ArrayList Tutorial | Edureka
Edureka!
 
Java Servlets
Nitin Pai
 
Java Multiple Choice Questions and Answers
Java Projects
 
Object-oriented concepts
BG Java EE Course
 
Introduction to Node js
Akshay Mathur
 
Sqlite
Kumar
 
android sqlite
Deepa Rani
 
Mvc architecture
Surbhi Panhalkar
 
Introduction to java
Ajay Sharma
 
Collections framework in java
yugandhar vadlamudi
 
android layouts
Deepa Rani
 
PORTFOLIO BY USING HTML & CSS
Meghaj Mallick
 
Memory Management & Garbage Collection
Abhishek Sur
 

Similar to Multiple Choice Questions on JAVA (object oriented programming) bank 7 -- abstract classes (20)

PPTX
Abstraction in java.pptx
AsifMulani17
 
PDF
Abstract classes and Methods in java
Harish Gyanani
 
DOCX
Master of Computer Application (MCA) – Semester 4 MC0078
Aravind NC
 
PPTX
Abstraction in java [abstract classes and Interfaces
Ahmed Nobi
 
PPTX
5- Overriding and Abstraction In Java
Ghadeer AlHasan
 
PDF
java-06inheritance
Arjun Shanka
 
PPTX
Abstract Class and Interface for Java Intoductory course.pptx
DrShamimAlMamun
 
PPTX
Abstract Class & Abstract Method in Core Java
MOHIT AGARWAL
 
PPTX
Polymorphism in java
Elizabeth alexander
 
PPTX
More oop in java
SAGARDAVE29
 
PPTX
object oriented programming unit two ppt
isiagnel2
 
PDF
Java abstract Keyword.pdf
SudhanshiBakre1
 
PPT
ABSTRACT CLASSES AND INTERFACES.ppt
JayanthiM15
 
PPTX
702641313-CS3391-OBJORIENTEDPS-Unit-2.pptx
SAJITHABANUS
 
PDF
Abstraction in Java: Abstract class and Interfaces
Jamsher bhanbhro
 
PPTX
UNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
SakkaravarthiS1
 
PPTX
Lecture-on-Object-Oriented-Programming-Language-Java.pptx
officialpriyanshu228
 
PDF
Inheritance
Sardar Alam
 
PDF
Java 06
Loida Igama
 
PPTX
Java presentation
Akteruzzaman .
 
Abstraction in java.pptx
AsifMulani17
 
Abstract classes and Methods in java
Harish Gyanani
 
Master of Computer Application (MCA) – Semester 4 MC0078
Aravind NC
 
Abstraction in java [abstract classes and Interfaces
Ahmed Nobi
 
5- Overriding and Abstraction In Java
Ghadeer AlHasan
 
java-06inheritance
Arjun Shanka
 
Abstract Class and Interface for Java Intoductory course.pptx
DrShamimAlMamun
 
Abstract Class & Abstract Method in Core Java
MOHIT AGARWAL
 
Polymorphism in java
Elizabeth alexander
 
More oop in java
SAGARDAVE29
 
object oriented programming unit two ppt
isiagnel2
 
Java abstract Keyword.pdf
SudhanshiBakre1
 
ABSTRACT CLASSES AND INTERFACES.ppt
JayanthiM15
 
702641313-CS3391-OBJORIENTEDPS-Unit-2.pptx
SAJITHABANUS
 
Abstraction in Java: Abstract class and Interfaces
Jamsher bhanbhro
 
UNIT-2.pptx CS3391 Inheritance , types, packages and Interfaces
SakkaravarthiS1
 
Lecture-on-Object-Oriented-Programming-Language-Java.pptx
officialpriyanshu228
 
Inheritance
Sardar Alam
 
Java 06
Loida Igama
 
Java presentation
Akteruzzaman .
 
Ad

More from Kuntal Bhowmick (20)

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

Recently uploaded (20)

PPTX
fatigue in aircraft structures-221113192308-0ad6dc8c.pptx
aviatecofficial
 
PPTX
GitOps_Without_K8s_Training_detailed git repository
DanialHabibi2
 
PPTX
Water Resources Engineering (CVE 728)--Slide 3.pptx
mohammedado3
 
PDF
Electrical Engineer operation Supervisor
ssaruntatapower143
 
PDF
AN EMPIRICAL STUDY ON THE USAGE OF SOCIAL MEDIA IN GERMAN B2C-ONLINE STORES
ijait
 
PDF
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
PPTX
Introduction to Internal Combustion Engines - Types, Working and Camparison.pptx
UtkarshPatil98
 
PPTX
2025 CGI Congres - Surviving agile v05.pptx
Derk-Jan de Grood
 
PPTX
Solar Thermal Energy System Seminar.pptx
Gpc Purapuza
 
PPTX
Lecture 1 Shell and Tube Heat exchanger-1.pptx
mailforillegalwork
 
PPTX
Introduction to Design of Machine Elements
PradeepKumarS27
 
PDF
MAD Unit - 1 Introduction of Android IT Department
JappanMavani
 
PPTX
How Industrial Project Management Differs From Construction.pptx
jamespit799
 
PPTX
The Role of Information Technology in Environmental Protectio....pptx
nallamillisriram
 
DOC
MRRS Strength and Durability of Concrete
CivilMythili
 
PDF
Design Thinking basics for Engineers.pdf
CMR University
 
PDF
REINFORCEMENT LEARNING IN DECISION MAKING SEMINAR REPORT
anushaashraf20
 
PPTX
Damage of stability of a ship and how its change .pptx
ehamadulhaque
 
PPTX
Knowledge Representation : Semantic Networks
Amity University, Patna
 
PPT
Footbinding.pptmnmkjkjkknmnnjkkkkkkkkkkkkkk
mamadoundiaye42742
 
fatigue in aircraft structures-221113192308-0ad6dc8c.pptx
aviatecofficial
 
GitOps_Without_K8s_Training_detailed git repository
DanialHabibi2
 
Water Resources Engineering (CVE 728)--Slide 3.pptx
mohammedado3
 
Electrical Engineer operation Supervisor
ssaruntatapower143
 
AN EMPIRICAL STUDY ON THE USAGE OF SOCIAL MEDIA IN GERMAN B2C-ONLINE STORES
ijait
 
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
Introduction to Internal Combustion Engines - Types, Working and Camparison.pptx
UtkarshPatil98
 
2025 CGI Congres - Surviving agile v05.pptx
Derk-Jan de Grood
 
Solar Thermal Energy System Seminar.pptx
Gpc Purapuza
 
Lecture 1 Shell and Tube Heat exchanger-1.pptx
mailforillegalwork
 
Introduction to Design of Machine Elements
PradeepKumarS27
 
MAD Unit - 1 Introduction of Android IT Department
JappanMavani
 
How Industrial Project Management Differs From Construction.pptx
jamespit799
 
The Role of Information Technology in Environmental Protectio....pptx
nallamillisriram
 
MRRS Strength and Durability of Concrete
CivilMythili
 
Design Thinking basics for Engineers.pdf
CMR University
 
REINFORCEMENT LEARNING IN DECISION MAKING SEMINAR REPORT
anushaashraf20
 
Damage of stability of a ship and how its change .pptx
ehamadulhaque
 
Knowledge Representation : Semantic Networks
Amity University, Patna
 
Footbinding.pptmnmkjkjkknmnnjkkkkkkkkkkkkkk
mamadoundiaye42742
 

Multiple Choice Questions on JAVA (object oriented programming) bank 7 -- abstract classes

  • 1. MCQs BANK Page: 1 Object Oriented Programming Topic: Abstract Classes 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.: 7
  • 2. MCQs Bank on Object Oriented Programming Topic : Abstract Classes MCQ No: 1 When the keyword _______ appears in a class definition, it means that zero or more of it’s methods are abstract. a) abstract b) default c) static d) public Page: 2
  • 3. MCQs Bank on Object Oriented Programming Topic : Abstract Classes MCQ No: 1 (Solution) Ans: a) abstract Explanation: When the keyword abstract appears in a class definition, it means that zero or more of it’s methods are abstract. Abstract class is a restricted class that cannot be used to create objects (to access it, it must be inherited from another class). Abstract method can only be used in an abstract class, and it does not have a body. The body is provided by the subclass (inherited from). Page: 3
  • 4. MCQs Bank on Object Oriented Programming Topic : Abstract Classes MCQ No: 2 An _________ method has no body. Fill in the blank. a) static b) abstract c) private d) public Page: 4
  • 5. MCQs Bank on Object Oriented Programming Topic : Abstract Classes MCQ No: 2 (Solution) Ans: b) abstract Explanation: An abstract method has no body. Some of the subclass has to override it and provide the implementation. Abstract methods are declaration only and it will not have implementation. It will not have a method body. A Java class containing an abstract class must be declared as abstract class. Page: 5
  • 6. MCQs Bank on Object Oriented Programming Topic : Abstract Classes MCQ No: 3 Objects cannot be created out of abstract class. True or False a) True b) False Page: 6
  • 7. MCQs Bank on Object Oriented Programming Topic : Abstract Classes MCQ No: 3 (Solution) Ans: a) True Explanation: Objects cannot be created out of abstract class. Abstract classes basically provide a guideline for the properties and methods of an object. Page: 7
  • 8. MCQs Bank on Object Oriented Programming Topic : Abstract Classes MCQ No: 4 An abstract class, which declared with the “abstract” keyword, cannot be instantiated. True or False? a) True b) False Page: 8
  • 9. MCQs Bank on Object Oriented Programming Topic : Abstract Classes MCQ No: 4 (Solution) Ans: a) True Explanation: An abstract class, which declared with the “abstract” keyword, cannot be instantiated. This is because in abstract class the methods are declared only without defining them. Abstract classes cannot be instantiated, but they can be sub classed. Page: 9
  • 10. MCQs Bank on Object Oriented Programming Topic : Abstract Classes MCQ No: 5 In order to use abstract classes, they have to be ______________ . Fill in the blank. a) subclassed b) sub-divided c) overridden d) overloaded Page: 10
  • 11. MCQs Bank on Object Oriented Programming Topic : Abstract Classes MCQ No: 5 (Solution) Ans: a) subclassed Explanation: In order to use abstract classes, they have to be subclassed. There are situations in which you want to define a superclass that declares the structure of a given abstraction without providing a complete implementation of every method. That is, sometimes you want to create a superclass that only defines generalized form that will be shared by all of its subclasses, leaving it to each subclass to fill in the details. Page: 11
  • 12. MCQs Bank on Object Oriented Programming Topic : Abstract Classes MCQ No: 6 ___________ are those methods that must be overridden by subclasses because they have no implementation specified in the superclass. Fill in the blank. a) default methods b) abstract methods c) static methods d) hidden methods Page: 12
  • 13. MCQs Bank on Object Oriented Programming Topic : Abstract Classes MCQ No: 6 (Solution) Ans: b) abstract methods Explanation: Consider a class Triangle. It has no meaning if area( ) is not defined. In this case, you want some way to ensure that a subclass does, indeed, override all necessary methods. Java’s solution to this problem is the abstract method. You can require that certain methods be overridden by subclasses by specifying the abstract type modifier. These methods are sometimes referred to as subclasser responsibility because they have no implementation specified in the superclass. Thus, a subclass must override them—it cannot simply use the version defined in the superclass. Page: 13
  • 14. MCQs Bank on Object Oriented Programming Topic : Abstract Classes MCQ No: 7 The correct way of declaring an abstract method is a) abstract return_type method_name(parameter-list); b) return_type method_name(parameter-list) abstract ; c) return_type abstract method_name(parameter-list); d) all are correct Page: 14
  • 15. MCQs Bank on Object Oriented Programming Topic : Abstract Classes MCQ No: 7 (Solution) Ans: a) abstract return_type method_name(parameter-list); Explanation: The correct way of declaring an abstract method is : abstract return_type method_name(parameter-list); As you can see, no method body is present. Any class that contains one or more abstract methods must also be declared abstract. Page: 15
  • 16. MCQs Bank on Object Oriented Programming Topic : Abstract Classes MCQ No: 8 There can be no objects of an abstract class. True or False a) True b) False Page: 16
  • 17. MCQs Bank on Object Oriented Programming Topic : Abstract Classes MCQ No: 8 (Solution) Ans: a) True Explanation: There can be no objects of an abstract class. That is, an abstract class cannot be directly instantiated with the new operator. Such objects would be useless, because an abstract class is not fully defined. Page: 17
  • 18. MCQs Bank on Object Oriented Programming Topic : Abstract Classes MCQ No: 9 Can you declare abstract constructors, or abstract static methods ? a) Yes b) No Page: 18
  • 19. MCQs Bank on Object Oriented Programming Topic : Abstract Classes MCQ No: 9 (Solution) Ans: b) No Explanation: You cannot declare abstract constructors, or abstract static methods. Constructors are invoked automatically when objects of a class is created using new operator. As an abstract class cannot be directly instantiated with the new operator so you cannot declare abstract constructors. static methods are class methods, that is shared by multiple objects(instances of the class) of a class, as an abstract class cannot be directly instantiated so it is not possible to declare abstract static methods. Page: 19
  • 20. MCQs Bank on Object Oriented Programming Topic : Abstract Classes MCQ No: 10 Any subclass of an abstract class must either implement all of the abstract methods in the superclass, or be itself declared abstract. True or False? a) True b) False Page: 20
  • 21. MCQs Bank on Object Oriented Programming Topic : Abstract Classes MCQ No: 10 (Solution) Ans: a) True Explanation: Any subclass of an abstract class must either implement all of the abstract methods in the superclass, or be itself declared abstract. Page: 21
  • 22. MCQs Bank on Object Oriented Programming Topic : Abstract Classes MCQ No: 11 Is it possible to create a reference to an abstract class so that it can be used to point to a subclass object ? a) Yes, Possible b) No, Not Possible Page: 22
  • 23. MCQs Bank on Object Oriented Programming Topic : Abstract Classes MCQ No: 11 (Solution) Ans: a) Yes, Possible Explanation: Although abstract classes cannot be used to instantiate objects, they can be used to create object references, because Java’s approach to run-time polymorphism is implemented through the use of superclass references. Thus, it must be possible to create a reference to an abstract class so that it can be used to point to a subclass object. It is through superclass reference variables that overridden methods are resolved at run time. Page: 23
  • 24. MCQs Bank on Object Oriented Programming Topic : Abstract Classes MCQ No: 12 Methods declared as final cannot be overridden. True or False a) True b) False Page: 24
  • 25. MCQs Bank on Object Oriented Programming Topic : Abstract Classes MCQ No: 12 (Solution) Ans: a) True Explanation: While method overriding is one of Java’s most powerful features, there will be times when you will want to prevent it from occurring. To disallow a method from being overridden, specify final as a modifier at the start of its declaration. Methods declared as final cannot be overridden. If you attempt to do so, a compile-time error will result. Page: 25
  • 26. MCQs Bank on Object Oriented Programming Topic : Abstract Classes MCQ No: 13 How would you will prevent a class from being inherited? a) By making the class abstract b) By adding a comment statement "Don't Inherit" c) Precede the class declaration with final d) Requesting others to not inherit the class Page: 26
  • 27. MCQs Bank on Object Oriented Programming Topic : Abstract Classes MCQ No: 13 (Solution) Ans: c) Precede the class declaration with final Explanation: Sometimes you will want to prevent a class from being inherited. To do this, precede the class declaration with final.Declaring a class as final implicitly declares all of its methods as final, too. Here is an example of a final class: final class A { // ... } // The following class is illegal. class B extends A { // ERROR! Can't subclass A // ... } Page: 27
  • 28. MCQs Bank on Object Oriented Programming Topic : Abstract Classes MCQ No: 14 It is illegal to declare a class as both abstract and final. Yes or No? a) Yes, it is illegal b) No, it is completely legal. Page: 28
  • 29. MCQs Bank on Object Oriented Programming Topic : Abstract Classes MCQ No: 14 (Solution) Ans: a) Yes, it is illegal Explanation: It is illegal to declare a class as both abstract and final since an abstract class is incomplete by itself and relies upon its subclasses to provide complete implementations. Page: 29