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

Object Oriented Programming - Polymorphism and Interfaces
Object Oriented Programming - Polymorphism and InterfacesObject Oriented Programming - Polymorphism and Interfaces
Object Oriented Programming - Polymorphism and InterfacesHabtamu Wolde
 
Java/J2EE interview Qestions
Java/J2EE interview QestionsJava/J2EE interview Qestions
Java/J2EE interview QestionsArun 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 InterfacesJamsher bhanbhro
 
Java interview questions and answers
Java interview questions and answersJava interview questions and answers
Java interview questions and answersMadhavendra Dutt
 
Java Core Parctical
Java Core ParcticalJava Core Parctical
Java Core ParcticalGaurav Mehta
 
Abstract classes and Methods in java
Abstract classes and Methods in javaAbstract classes and Methods in java
Abstract classes and Methods in javaHarish Gyanani
 
Implementing polymorphism
Implementing polymorphismImplementing polymorphism
Implementing polymorphismrajshreemuthiah
 
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 jobGaruda Trainings
 
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 questionsVinay 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.pdfarchitcreation
 
Java abstract Keyword.pdf
Java abstract Keyword.pdfJava abstract Keyword.pdf
Java abstract Keyword.pdfSudhanshiBakre1
 

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.pdfarihantkitchenmart
 
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.pdfarihantkitchenmart
 
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.pdfarihantkitchenmart
 
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.pdfarihantkitchenmart
 
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 .pdfarihantkitchenmart
 
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 .pdfarihantkitchenmart
 
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.pdfarihantkitchenmart
 
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.pdfarihantkitchenmart
 
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.pdfarihantkitchenmart
 
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.pdfarihantkitchenmart
 
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.pdfarihantkitchenmart
 
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.pdfarihantkitchenmart
 
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.pdfarihantkitchenmart
 
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.pdfarihantkitchenmart
 
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.pdfarihantkitchenmart
 
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.pdfarihantkitchenmart
 
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.pdfarihantkitchenmart
 
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 .pdfarihantkitchenmart
 
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.pdfarihantkitchenmart
 
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.pdfarihantkitchenmart
 

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 to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 

Recently uploaded (20)

How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 

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.