SlideShare a Scribd company logo
What are abstract classes?
Don't interfaces also allow for polymorphism? If so, what is the difference between abstract
classes and interfaces? Which would you choose when?
Solution
(i)
Abstract class:
abstract class is a class that is declared abstract.
-It may include or may not include abstract method.
-It can be subclassed ,but cannot be instantiated.
-A abstract method is a method that is declared without an implementation.
e.g abstract void drive1()
If a class includes abstract methods,then the class declare itself as abstract.
e.g
public abstract class DriveCar {
abstract void drive1();
}
(ii)
Interface allow polymorphism.It formalize polymorphism.
If two elements realizes the same interface,then only these are polymorphic w.r.t a set of
behaviors .
It gives good description of working of polymorphism & allows us to define polymorphism in a
declarative way.
(iii)
Difference between abstract classes & interfaces:
It can extent only one class or one abstract class at a time.
It can have abstract and non-abstract methods.
(iv)
We would use abstract class in the following scenerio:
(i)When we want to use inheritance as it provides a common base class implementation to
derived classes.
(ii)When we want to declare non-public method as Interface has all methods as public only.
(iii)When we want to add methods in future because if you add a method to interface,then all of
the classes that are already implemented ,needed to be changed.
We would use interface in the following scenerio:
Interface is used when we need to implement multiple inheritance.Abstract ClassInterface
It can extent only one class or one abstract class at a time.
It can extent any number of interfaces at a time.
It can have abstract and non-abstract methods.
It can have only abstract methods.It can have protected ,public abstract methods.It can have only
public abstract method.abstract keyword is used to declare it.interface keyword is used to declare
itA class can extent only one abstract class.
A class can implement any number of interfacesIt can be inherited by a class or an abstract class.
It can be extended only by interfaces.Classes has to implement them instead of extend.
It can have static methods,main methodds and constructor.
It can't have static methods,main methodds and constructor.

More Related Content

Similar to What are abstract classes Dont interfaces also allow for polymo.pdf

Java 6.pptx
Java 6.pptxJava 6.pptx
Java 6.pptx
usmanusman720379
 
Object Oriented Programming - Polymorphism and Interfaces
Object Oriented Programming - Polymorphism and InterfacesObject Oriented Programming - Polymorphism and Interfaces
Object Oriented Programming - Polymorphism and Interfaces
Habtamu Wolde
 
Java/J2EE interview Qestions
Java/J2EE interview QestionsJava/J2EE interview Qestions
Java/J2EE interview Qestions
Arun Vasanth
 
Complete java&j2ee
Complete java&j2eeComplete java&j2ee
Complete java&j2eeShiva Cse
 
Abstraction in Java: Abstract class and Interfaces
Abstraction in  Java: Abstract class and InterfacesAbstraction in  Java: Abstract class and Interfaces
Abstraction in Java: Abstract class and Interfaces
Jamsher bhanbhro
 
Java interview questions and answers
Java interview questions and answersJava interview questions and answers
Java interview questions and answers
Madhavendra Dutt
 
Java Core Parctical
Java Core ParcticalJava Core Parctical
Java Core Parctical
Gaurav Mehta
 
Abstract classes and Methods in java
Abstract classes and Methods in javaAbstract classes and Methods in java
Abstract classes and Methods in java
Harish Gyanani
 
Implementing polymorphism
Implementing polymorphismImplementing polymorphism
Implementing polymorphism
rajshreemuthiah
 
Core java interview faq
Core java interview faqCore java interview faq
Core java interview faqKumaran K
 
Basic java important interview questions and answers to secure a job
Basic java important interview questions and answers to secure a jobBasic java important interview questions and answers to secure a job
Basic java important interview questions and answers to secure a job
Garuda Trainings
 
Java Core
Java CoreJava Core
Java Core
Gaurav Mehta
 
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
 
Core java interview questions
Core java interview questionsCore java interview questions
Core java interview questions
Vinay Kumar
 
What is an interface How is extending a class different from implem.pdf
What is an interface How is extending a class different from implem.pdfWhat is an interface How is extending a class different from implem.pdf
What is an interface How is extending a class different from implem.pdf
architcreation
 
Faqs in java
Faqs in javaFaqs in java
Faqs in java
prathap kumar
 
Java abstract Keyword.pdf
Java abstract Keyword.pdfJava abstract Keyword.pdf
Java abstract Keyword.pdf
SudhanshiBakre1
 

Similar to What are abstract classes Dont interfaces also allow for polymo.pdf (20)

Vvi
VviVvi
Vvi
 
Java 6.pptx
Java 6.pptxJava 6.pptx
Java 6.pptx
 
Object Oriented Programming - Polymorphism and Interfaces
Object Oriented Programming - Polymorphism and InterfacesObject Oriented Programming - Polymorphism and Interfaces
Object Oriented Programming - Polymorphism and Interfaces
 
Java/J2EE interview Qestions
Java/J2EE interview QestionsJava/J2EE interview Qestions
Java/J2EE interview Qestions
 
Complete java&j2ee
Complete java&j2eeComplete java&j2ee
Complete java&j2ee
 
Abstraction in Java: Abstract class and Interfaces
Abstraction in  Java: Abstract class and InterfacesAbstraction in  Java: Abstract class and Interfaces
Abstraction in Java: Abstract class and Interfaces
 
Core java questions
Core java questionsCore java questions
Core java questions
 
Java interview questions and answers
Java interview questions and answersJava interview questions and answers
Java interview questions and answers
 
C# question answers
C# question answersC# question answers
C# question answers
 
Java Core Parctical
Java Core ParcticalJava Core Parctical
Java Core Parctical
 
Abstract classes and Methods in java
Abstract classes and Methods in javaAbstract classes and Methods in java
Abstract classes and Methods in java
 
Implementing polymorphism
Implementing polymorphismImplementing polymorphism
Implementing polymorphism
 
Core java interview faq
Core java interview faqCore java interview faq
Core java interview faq
 
Basic java important interview questions and answers to secure a job
Basic java important interview questions and answers to secure a jobBasic java important interview questions and answers to secure a job
Basic java important interview questions and answers to secure a job
 
Java Core
Java CoreJava Core
Java Core
 
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)
 
Core java interview questions
Core java interview questionsCore java interview questions
Core java interview questions
 
What is an interface How is extending a class different from implem.pdf
What is an interface How is extending a class different from implem.pdfWhat is an interface How is extending a class different from implem.pdf
What is an interface How is extending a class different from implem.pdf
 
Faqs in java
Faqs in javaFaqs in java
Faqs in java
 
Java abstract Keyword.pdf
Java abstract Keyword.pdfJava abstract Keyword.pdf
Java abstract Keyword.pdf
 

More from arihantkitchenmart

Identify the four factors of production, and tell what type of incom.pdf
Identify the four factors of production, and tell what type of incom.pdfIdentify the four factors of production, and tell what type of incom.pdf
Identify the four factors of production, and tell what type of incom.pdf
arihantkitchenmart
 
Identify the membranes that line the cavity surrounding the lungs. p.pdf
Identify the membranes that line the cavity surrounding the lungs.  p.pdfIdentify the membranes that line the cavity surrounding the lungs.  p.pdf
Identify the membranes that line the cavity surrounding the lungs. p.pdf
arihantkitchenmart
 
How is explicit knowledge different from tacit knowledgeSolutio.pdf
How is explicit knowledge different from tacit knowledgeSolutio.pdfHow is explicit knowledge different from tacit knowledgeSolutio.pdf
How is explicit knowledge different from tacit knowledgeSolutio.pdf
arihantkitchenmart
 
How did printing technology impact literacy and education How d.pdf
How did printing technology impact literacy and education How d.pdfHow did printing technology impact literacy and education How d.pdf
How did printing technology impact literacy and education How d.pdf
arihantkitchenmart
 
Could a violent video games make a person become a terrorist .pdf
Could a violent video games make a person become a terrorist  .pdfCould a violent video games make a person become a terrorist  .pdf
Could a violent video games make a person become a terrorist .pdf
arihantkitchenmart
 
For each of the four rows in Table 5.10-1, organize and combine the .pdf
For each of the four rows in Table 5.10-1, organize and combine the .pdfFor each of the four rows in Table 5.10-1, organize and combine the .pdf
For each of the four rows in Table 5.10-1, organize and combine the .pdf
arihantkitchenmart
 
Applying change management theoryto discuss the integration ofone of.pdf
Applying change management theoryto discuss the integration ofone of.pdfApplying change management theoryto discuss the integration ofone of.pdf
Applying change management theoryto discuss the integration ofone of.pdf
arihantkitchenmart
 
Albinism in humans is inherited as a simple recessive trait. For the.pdf
Albinism in humans is inherited as a simple recessive trait. For the.pdfAlbinism in humans is inherited as a simple recessive trait. For the.pdf
Albinism in humans is inherited as a simple recessive trait. For the.pdf
arihantkitchenmart
 
Exercise 3 Cell Structure Name Tacabac 1. Cells in the body have a fl.pdf
Exercise 3 Cell Structure Name Tacabac 1. Cells in the body have a fl.pdfExercise 3 Cell Structure Name Tacabac 1. Cells in the body have a fl.pdf
Exercise 3 Cell Structure Name Tacabac 1. Cells in the body have a fl.pdf
arihantkitchenmart
 
Does isoforms have do do anything with transcription and translat.pdf
Does isoforms have do do anything with transcription and translat.pdfDoes isoforms have do do anything with transcription and translat.pdf
Does isoforms have do do anything with transcription and translat.pdf
arihantkitchenmart
 
discuss the evolutionary significance of bilateral symmetry, cephali.pdf
discuss the evolutionary significance of bilateral symmetry, cephali.pdfdiscuss the evolutionary significance of bilateral symmetry, cephali.pdf
discuss the evolutionary significance of bilateral symmetry, cephali.pdf
arihantkitchenmart
 
Compare the best-case time complexities of Exchange Sort and Inserti.pdf
Compare the best-case time complexities of Exchange Sort and Inserti.pdfCompare the best-case time complexities of Exchange Sort and Inserti.pdf
Compare the best-case time complexities of Exchange Sort and Inserti.pdf
arihantkitchenmart
 
When we test your Fraction.java we will use the given FractionTester.pdf
When we test your Fraction.java we will use the given FractionTester.pdfWhen we test your Fraction.java we will use the given FractionTester.pdf
When we test your Fraction.java we will use the given FractionTester.pdf
arihantkitchenmart
 
What are transposons How have they been exploited for bacterial gen.pdf
What are transposons How have they been exploited for bacterial gen.pdfWhat are transposons How have they been exploited for bacterial gen.pdf
What are transposons How have they been exploited for bacterial gen.pdf
arihantkitchenmart
 
A population of 1000 dung beetles was split into live populations whe.pdf
A population of 1000 dung beetles was split into live populations whe.pdfA population of 1000 dung beetles was split into live populations whe.pdf
A population of 1000 dung beetles was split into live populations whe.pdf
arihantkitchenmart
 
Which of these sentences are TRUE in Java Select all that apply, You.pdf
Which of these sentences are TRUE in Java Select all that apply, You.pdfWhich of these sentences are TRUE in Java Select all that apply, You.pdf
Which of these sentences are TRUE in Java Select all that apply, You.pdf
arihantkitchenmart
 
Which of the following is a stated principle of a NYSE report identi.pdf
Which of the following is a stated principle of a NYSE report identi.pdfWhich of the following is a stated principle of a NYSE report identi.pdf
Which of the following is a stated principle of a NYSE report identi.pdf
arihantkitchenmart
 
Why do some elderly take B12 sublingually or transdermally Provide .pdf
Why do some elderly take B12 sublingually or transdermally Provide .pdfWhy do some elderly take B12 sublingually or transdermally Provide .pdf
Why do some elderly take B12 sublingually or transdermally Provide .pdf
arihantkitchenmart
 
Why is water a more hospitable environment for life than dry land O.pdf
Why is water a more hospitable environment for life than dry land  O.pdfWhy is water a more hospitable environment for life than dry land  O.pdf
Why is water a more hospitable environment for life than dry land O.pdf
arihantkitchenmart
 
Which of the following triploblastic invertebrates is incorrectly ma.pdf
Which of the following triploblastic invertebrates is incorrectly ma.pdfWhich of the following triploblastic invertebrates is incorrectly ma.pdf
Which of the following triploblastic invertebrates is incorrectly ma.pdf
arihantkitchenmart
 

More from arihantkitchenmart (20)

Identify the four factors of production, and tell what type of incom.pdf
Identify the four factors of production, and tell what type of incom.pdfIdentify the four factors of production, and tell what type of incom.pdf
Identify the four factors of production, and tell what type of incom.pdf
 
Identify the membranes that line the cavity surrounding the lungs. p.pdf
Identify the membranes that line the cavity surrounding the lungs.  p.pdfIdentify the membranes that line the cavity surrounding the lungs.  p.pdf
Identify the membranes that line the cavity surrounding the lungs. p.pdf
 
How is explicit knowledge different from tacit knowledgeSolutio.pdf
How is explicit knowledge different from tacit knowledgeSolutio.pdfHow is explicit knowledge different from tacit knowledgeSolutio.pdf
How is explicit knowledge different from tacit knowledgeSolutio.pdf
 
How did printing technology impact literacy and education How d.pdf
How did printing technology impact literacy and education How d.pdfHow did printing technology impact literacy and education How d.pdf
How did printing technology impact literacy and education How d.pdf
 
Could a violent video games make a person become a terrorist .pdf
Could a violent video games make a person become a terrorist  .pdfCould a violent video games make a person become a terrorist  .pdf
Could a violent video games make a person become a terrorist .pdf
 
For each of the four rows in Table 5.10-1, organize and combine the .pdf
For each of the four rows in Table 5.10-1, organize and combine the .pdfFor each of the four rows in Table 5.10-1, organize and combine the .pdf
For each of the four rows in Table 5.10-1, organize and combine the .pdf
 
Applying change management theoryto discuss the integration ofone of.pdf
Applying change management theoryto discuss the integration ofone of.pdfApplying change management theoryto discuss the integration ofone of.pdf
Applying change management theoryto discuss the integration ofone of.pdf
 
Albinism in humans is inherited as a simple recessive trait. For the.pdf
Albinism in humans is inherited as a simple recessive trait. For the.pdfAlbinism in humans is inherited as a simple recessive trait. For the.pdf
Albinism in humans is inherited as a simple recessive trait. For the.pdf
 
Exercise 3 Cell Structure Name Tacabac 1. Cells in the body have a fl.pdf
Exercise 3 Cell Structure Name Tacabac 1. Cells in the body have a fl.pdfExercise 3 Cell Structure Name Tacabac 1. Cells in the body have a fl.pdf
Exercise 3 Cell Structure Name Tacabac 1. Cells in the body have a fl.pdf
 
Does isoforms have do do anything with transcription and translat.pdf
Does isoforms have do do anything with transcription and translat.pdfDoes isoforms have do do anything with transcription and translat.pdf
Does isoforms have do do anything with transcription and translat.pdf
 
discuss the evolutionary significance of bilateral symmetry, cephali.pdf
discuss the evolutionary significance of bilateral symmetry, cephali.pdfdiscuss the evolutionary significance of bilateral symmetry, cephali.pdf
discuss the evolutionary significance of bilateral symmetry, cephali.pdf
 
Compare the best-case time complexities of Exchange Sort and Inserti.pdf
Compare the best-case time complexities of Exchange Sort and Inserti.pdfCompare the best-case time complexities of Exchange Sort and Inserti.pdf
Compare the best-case time complexities of Exchange Sort and Inserti.pdf
 
When we test your Fraction.java we will use the given FractionTester.pdf
When we test your Fraction.java we will use the given FractionTester.pdfWhen we test your Fraction.java we will use the given FractionTester.pdf
When we test your Fraction.java we will use the given FractionTester.pdf
 
What are transposons How have they been exploited for bacterial gen.pdf
What are transposons How have they been exploited for bacterial gen.pdfWhat are transposons How have they been exploited for bacterial gen.pdf
What are transposons How have they been exploited for bacterial gen.pdf
 
A population of 1000 dung beetles was split into live populations whe.pdf
A population of 1000 dung beetles was split into live populations whe.pdfA population of 1000 dung beetles was split into live populations whe.pdf
A population of 1000 dung beetles was split into live populations whe.pdf
 
Which of these sentences are TRUE in Java Select all that apply, You.pdf
Which of these sentences are TRUE in Java Select all that apply, You.pdfWhich of these sentences are TRUE in Java Select all that apply, You.pdf
Which of these sentences are TRUE in Java Select all that apply, You.pdf
 
Which of the following is a stated principle of a NYSE report identi.pdf
Which of the following is a stated principle of a NYSE report identi.pdfWhich of the following is a stated principle of a NYSE report identi.pdf
Which of the following is a stated principle of a NYSE report identi.pdf
 
Why do some elderly take B12 sublingually or transdermally Provide .pdf
Why do some elderly take B12 sublingually or transdermally Provide .pdfWhy do some elderly take B12 sublingually or transdermally Provide .pdf
Why do some elderly take B12 sublingually or transdermally Provide .pdf
 
Why is water a more hospitable environment for life than dry land O.pdf
Why is water a more hospitable environment for life than dry land  O.pdfWhy is water a more hospitable environment for life than dry land  O.pdf
Why is water a more hospitable environment for life than dry land O.pdf
 
Which of the following triploblastic invertebrates is incorrectly ma.pdf
Which of the following triploblastic invertebrates is incorrectly ma.pdfWhich of the following triploblastic invertebrates is incorrectly ma.pdf
Which of the following triploblastic invertebrates is incorrectly ma.pdf
 

Recently uploaded

How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
Wasim Ak
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
deeptiverma2406
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
Krisztián Száraz
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
JEE1_This_section_contains_FOUR_ questions
JEE1_This_section_contains_FOUR_ questionsJEE1_This_section_contains_FOUR_ questions
JEE1_This_section_contains_FOUR_ questions
ShivajiThube2
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
chanes7
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 

Recently uploaded (20)

How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
JEE1_This_section_contains_FOUR_ questions
JEE1_This_section_contains_FOUR_ questionsJEE1_This_section_contains_FOUR_ questions
JEE1_This_section_contains_FOUR_ questions
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 

What are abstract classes Dont interfaces also allow for polymo.pdf

  • 1. What are abstract classes? Don't interfaces also allow for polymorphism? If so, what is the difference between abstract classes and interfaces? Which would you choose when? Solution (i) Abstract class: abstract class is a class that is declared abstract. -It may include or may not include abstract method. -It can be subclassed ,but cannot be instantiated. -A abstract method is a method that is declared without an implementation. e.g abstract void drive1() If a class includes abstract methods,then the class declare itself as abstract. e.g public abstract class DriveCar { abstract void drive1(); } (ii) Interface allow polymorphism.It formalize polymorphism. If two elements realizes the same interface,then only these are polymorphic w.r.t a set of behaviors . It gives good description of working of polymorphism & allows us to define polymorphism in a declarative way. (iii) Difference between abstract classes & interfaces: It can extent only one class or one abstract class at a time. It can have abstract and non-abstract methods. (iv) We would use abstract class in the following scenerio: (i)When we want to use inheritance as it provides a common base class implementation to derived classes. (ii)When we want to declare non-public method as Interface has all methods as public only.
  • 2. (iii)When we want to add methods in future because if you add a method to interface,then all of the classes that are already implemented ,needed to be changed. We would use interface in the following scenerio: Interface is used when we need to implement multiple inheritance.Abstract ClassInterface It can extent only one class or one abstract class at a time. It can extent any number of interfaces at a time. It can have abstract and non-abstract methods. It can have only abstract methods.It can have protected ,public abstract methods.It can have only public abstract method.abstract keyword is used to declare it.interface keyword is used to declare itA class can extent only one abstract class. A class can implement any number of interfacesIt can be inherited by a class or an abstract class. It can be extended only by interfaces.Classes has to implement them instead of extend. It can have static methods,main methodds and constructor. It can't have static methods,main methodds and constructor.