SlideShare a Scribd company logo
1 of 7
Abstract Class and Interface
1
Prepared by
Dr.S.Raja Ratna
2
Abstract Class
• An abstract class is a class that is designed to be specifically used
as a base class.
• An abstract class contains at least one pure virtual function. You
declare a pure virtual function by using a pure specifier ( = 0 ) in the
declaration of a virtual member function in the class declaration.
• An abstract function has no implementation and must be in an
abstract class. It can only be declared.
Rules for Abstract Class
● We cannot create objects of an abstract class.
● We can derive classes from them, and use their data members and
member functions (except pure virtual functions).
● Abstract classes are the way to achieve abstraction in C++.
● Abstraction in C++ is the process to hide the internal details and showing
functionality only.
● Abstraction can be achieved by two ways:
- Abstract class
- Interface
● Abstract class and interface both can have abstract methods which are
necessary for abstraction.
3
● 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: It can only be used in an abstract class, and it does not
have a body. The body is provided by the subclass (inherited from).
● An abstract member is implicitly virtual. The abstract can be called as pure
virtual in some of the languages.
● Abstraction: Abstraction is not a real implementation, it means showing
only necessary things that is no actual implementation how is about.
Abstract class is one opposite concept it is used for different purpose.
4
5
Interface
● An interface describes the behavior or capabilities of a C++ class
without committing to a particular implementation of that class.
● C++ has no built-in concepts of interfaces. You can implement it using
abstract classes which contains only pure virtual functions.
● Since it allows multiple inheritance, you can inherit this class to create
another class which will then contain this interface in it.
● Any class derived from the pure abstract class (Interface) must
implement all of the methods of the base class i.e. Interface. Interface
pointers can be passed to functions and classes thereby we can call the
functions of the derived class from there itself.
Abstract Class vs. Interface
● Abstract Class and Interface are used in Java. The Abstract class and
Interface both are used to have abstraction. An abstract class contains an
abstract keyword on the declaration whereas an Interface is a sketch that is
used to implement a class.
● An abstract class allows you to create functionality that subclasses can
implement or override. An interface only allows you to define functionality,
not implement it. And whereas a class can extend only one abstract class, it
can take advantage of multiple interfaces.
6
Abstract Class vs. Interface
● The C++ interfaces are implemented using abstract classes and these
abstract classes should not be confused with data abstraction which is a
concept of keeping implementation details separate from associated data.
● A class is made abstract by declaring at least one of its functions as pure
virtual function. A pure virtual function is specified by placing "= 0" in its
declaration
7

More Related Content

Similar to Abstract Class and Interface.pdf

BCA Abstraction.pptx
BCA Abstraction.pptxBCA Abstraction.pptx
BCA Abstraction.pptxsarthakgithub
 
Abstraction in java [abstract classes and Interfaces
Abstraction in java [abstract classes and InterfacesAbstraction in java [abstract classes and Interfaces
Abstraction in java [abstract classes and InterfacesAhmed Nobi
 
Master of Computer Application (MCA) – Semester 4 MC0078
Master of Computer Application (MCA) – Semester 4  MC0078Master of Computer Application (MCA) – Semester 4  MC0078
Master of Computer Application (MCA) – Semester 4 MC0078Aravind NC
 
ABSTRACT CLASSES AND INTERFACES.ppt
ABSTRACT CLASSES AND INTERFACES.pptABSTRACT CLASSES AND INTERFACES.ppt
ABSTRACT CLASSES AND INTERFACES.pptJayanthiM15
 
8abstact class in c#
8abstact class in c#8abstact class in c#
8abstact class in c#Sireesh K
 
Core java notes with examples
Core java notes with examplesCore java notes with examples
Core java notes with examplesbindur87
 
06_OOVP.pptx object oriented and visual programming
06_OOVP.pptx object oriented and visual programming06_OOVP.pptx object oriented and visual programming
06_OOVP.pptx object oriented and visual programmingdeffa5
 
Java abstract Keyword.pdf
Java abstract Keyword.pdfJava abstract Keyword.pdf
Java abstract Keyword.pdfSudhanshiBakre1
 
Advanced Programming _Abstract Classes vs Interfaces (Java)
Advanced Programming _Abstract Classes vs Interfaces (Java)Advanced Programming _Abstract Classes vs Interfaces (Java)
Advanced Programming _Abstract Classes vs Interfaces (Java)Professor Lili Saghafi
 
Introduction to oop
Introduction to oopIntroduction to oop
Introduction to oopcolleges
 
Abstract classes and Methods in java
Abstract classes and Methods in javaAbstract classes and Methods in java
Abstract classes and Methods in javaHarish Gyanani
 
Interfaces in java
Interfaces in javaInterfaces in java
Interfaces in javaShiv Mehmi
 
Abstract_descrption
Abstract_descrptionAbstract_descrption
Abstract_descrptionMahi Mca
 

Similar to Abstract Class and Interface.pdf (20)

Interface
InterfaceInterface
Interface
 
Oop
OopOop
Oop
 
BCA Abstraction.pptx
BCA Abstraction.pptxBCA Abstraction.pptx
BCA Abstraction.pptx
 
Abstraction in java [abstract classes and Interfaces
Abstraction in java [abstract classes and InterfacesAbstraction in java [abstract classes and Interfaces
Abstraction in java [abstract classes and Interfaces
 
Master of Computer Application (MCA) – Semester 4 MC0078
Master of Computer Application (MCA) – Semester 4  MC0078Master of Computer Application (MCA) – Semester 4  MC0078
Master of Computer Application (MCA) – Semester 4 MC0078
 
Lecture 18
Lecture 18Lecture 18
Lecture 18
 
ABSTRACT CLASSES AND INTERFACES.ppt
ABSTRACT CLASSES AND INTERFACES.pptABSTRACT CLASSES AND INTERFACES.ppt
ABSTRACT CLASSES AND INTERFACES.ppt
 
8abstact class in c#
8abstact class in c#8abstact class in c#
8abstact class in c#
 
Core java notes with examples
Core java notes with examplesCore java notes with examples
Core java notes with examples
 
06_OOVP.pptx object oriented and visual programming
06_OOVP.pptx object oriented and visual programming06_OOVP.pptx object oriented and visual programming
06_OOVP.pptx object oriented and visual programming
 
Java abstract Keyword.pdf
Java abstract Keyword.pdfJava abstract Keyword.pdf
Java abstract Keyword.pdf
 
Advanced Programming _Abstract Classes vs Interfaces (Java)
Advanced Programming _Abstract Classes vs Interfaces (Java)Advanced Programming _Abstract Classes vs Interfaces (Java)
Advanced Programming _Abstract Classes vs Interfaces (Java)
 
Introduction to oop
Introduction to oopIntroduction to oop
Introduction to oop
 
Lecture 10
Lecture 10Lecture 10
Lecture 10
 
Abstract classes and Methods in java
Abstract classes and Methods in javaAbstract classes and Methods in java
Abstract classes and Methods in java
 
Interfaces in java
Interfaces in javaInterfaces in java
Interfaces in java
 
javainterface
javainterfacejavainterface
javainterface
 
Abstract class in java
Abstract class in javaAbstract class in java
Abstract class in java
 
Abstract_descrption
Abstract_descrptionAbstract_descrption
Abstract_descrption
 
9 abstract interface
9 abstract interface9 abstract interface
9 abstract interface
 

More from rajaratna4

Memory and Cache Coherence in Multiprocessor System.pdf
Memory and Cache Coherence in Multiprocessor System.pdfMemory and Cache Coherence in Multiprocessor System.pdf
Memory and Cache Coherence in Multiprocessor System.pdfrajaratna4
 
Multicore processor.pdf
Multicore processor.pdfMulticore processor.pdf
Multicore processor.pdfrajaratna4
 
Hardware Multithreading.pdf
Hardware Multithreading.pdfHardware Multithreading.pdf
Hardware Multithreading.pdfrajaratna4
 
Flynn's classification.pdf
Flynn's classification.pdfFlynn's classification.pdf
Flynn's classification.pdfrajaratna4
 
Classes and Errors.pdf
Classes and Errors.pdfClasses and Errors.pdf
Classes and Errors.pdfrajaratna4
 
Example for Virtual and Pure Virtual function.pdf
Example for Virtual and Pure Virtual function.pdfExample for Virtual and Pure Virtual function.pdf
Example for Virtual and Pure Virtual function.pdfrajaratna4
 
Example for Abstract Class and Interface.pdf
Example for Abstract Class and Interface.pdfExample for Abstract Class and Interface.pdf
Example for Abstract Class and Interface.pdfrajaratna4
 

More from rajaratna4 (8)

Memory and Cache Coherence in Multiprocessor System.pdf
Memory and Cache Coherence in Multiprocessor System.pdfMemory and Cache Coherence in Multiprocessor System.pdf
Memory and Cache Coherence in Multiprocessor System.pdf
 
Multicore processor.pdf
Multicore processor.pdfMulticore processor.pdf
Multicore processor.pdf
 
Hardware Multithreading.pdf
Hardware Multithreading.pdfHardware Multithreading.pdf
Hardware Multithreading.pdf
 
Flynn's classification.pdf
Flynn's classification.pdfFlynn's classification.pdf
Flynn's classification.pdf
 
Classes and Errors.pdf
Classes and Errors.pdfClasses and Errors.pdf
Classes and Errors.pdf
 
STLStack.pdf
STLStack.pdfSTLStack.pdf
STLStack.pdf
 
Example for Virtual and Pure Virtual function.pdf
Example for Virtual and Pure Virtual function.pdfExample for Virtual and Pure Virtual function.pdf
Example for Virtual and Pure Virtual function.pdf
 
Example for Abstract Class and Interface.pdf
Example for Abstract Class and Interface.pdfExample for Abstract Class and Interface.pdf
Example for Abstract Class and Interface.pdf
 

Recently uploaded

Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapRishantSharmaFr
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesRAJNEESHKUMAR341697
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxmaisarahman1
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxSCMS School of Architecture
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdfKamal Acharya
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Servicemeghakumariji156
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdfKamal Acharya
 
Air Compressor reciprocating single stage
Air Compressor reciprocating single stageAir Compressor reciprocating single stage
Air Compressor reciprocating single stageAbc194748
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.Kamal Acharya
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesMayuraD1
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startQuintin Balsdon
 
Computer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersComputer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersMairaAshraf6
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwaitjaanualu31
 
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...Health
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXssuser89054b
 
Learn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic MarksLearn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic MarksMagic Marks
 
Bridge Jacking Design Sample Calculation.pptx
Bridge Jacking Design Sample Calculation.pptxBridge Jacking Design Sample Calculation.pptx
Bridge Jacking Design Sample Calculation.pptxnuruddin69
 

Recently uploaded (20)

Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planes
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Air Compressor reciprocating single stage
Air Compressor reciprocating single stageAir Compressor reciprocating single stage
Air Compressor reciprocating single stage
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Computer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersComputer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to Computers
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
 
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Learn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic MarksLearn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic Marks
 
Bridge Jacking Design Sample Calculation.pptx
Bridge Jacking Design Sample Calculation.pptxBridge Jacking Design Sample Calculation.pptx
Bridge Jacking Design Sample Calculation.pptx
 

Abstract Class and Interface.pdf

  • 1. Abstract Class and Interface 1 Prepared by Dr.S.Raja Ratna
  • 2. 2 Abstract Class • An abstract class is a class that is designed to be specifically used as a base class. • An abstract class contains at least one pure virtual function. You declare a pure virtual function by using a pure specifier ( = 0 ) in the declaration of a virtual member function in the class declaration. • An abstract function has no implementation and must be in an abstract class. It can only be declared.
  • 3. Rules for Abstract Class ● We cannot create objects of an abstract class. ● We can derive classes from them, and use their data members and member functions (except pure virtual functions). ● Abstract classes are the way to achieve abstraction in C++. ● Abstraction in C++ is the process to hide the internal details and showing functionality only. ● Abstraction can be achieved by two ways: - Abstract class - Interface ● Abstract class and interface both can have abstract methods which are necessary for abstraction. 3
  • 4. ● 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: It can only be used in an abstract class, and it does not have a body. The body is provided by the subclass (inherited from). ● An abstract member is implicitly virtual. The abstract can be called as pure virtual in some of the languages. ● Abstraction: Abstraction is not a real implementation, it means showing only necessary things that is no actual implementation how is about. Abstract class is one opposite concept it is used for different purpose. 4
  • 5. 5 Interface ● An interface describes the behavior or capabilities of a C++ class without committing to a particular implementation of that class. ● C++ has no built-in concepts of interfaces. You can implement it using abstract classes which contains only pure virtual functions. ● Since it allows multiple inheritance, you can inherit this class to create another class which will then contain this interface in it. ● Any class derived from the pure abstract class (Interface) must implement all of the methods of the base class i.e. Interface. Interface pointers can be passed to functions and classes thereby we can call the functions of the derived class from there itself.
  • 6. Abstract Class vs. Interface ● Abstract Class and Interface are used in Java. The Abstract class and Interface both are used to have abstraction. An abstract class contains an abstract keyword on the declaration whereas an Interface is a sketch that is used to implement a class. ● An abstract class allows you to create functionality that subclasses can implement or override. An interface only allows you to define functionality, not implement it. And whereas a class can extend only one abstract class, it can take advantage of multiple interfaces. 6
  • 7. Abstract Class vs. Interface ● The C++ interfaces are implemented using abstract classes and these abstract classes should not be confused with data abstraction which is a concept of keeping implementation details separate from associated data. ● A class is made abstract by declaring at least one of its functions as pure virtual function. A pure virtual function is specified by placing "= 0" in its declaration 7