SlideShare a Scribd company logo
Abstract Class
Class Objectives:
Why abstract class?
How to Implement it?
“Don’t be Hidden”
Java Abstract Class
The abstract class in Java cannot be instantiated (we cannot create objects of
abstract classes). We use the abstract keyword to declare an abstract class.
For example,
An abstract class can have both the regular methods and
abstract methods. For example,
Java Abstract Method
A method that doesn't have its body is known as an
abstract method. We use the same abstract keyword to
create abstract methods. For example,
If a class contains an abstract method, then the class
should be declared abstract. Otherwise, it will generate
an error. For example,
Java Abstract Class and Method
Though abstract classes cannot be instantiated, we can create
subclasses from it. We can then access members of the abstract
class using the object of the subclass. For example,
Implementing Abstract Methods
If the abstract class
includes any abstract
method, then all the child
classes inherited from the
abstract superclass must
provide the
implementation of the
abstract method. For
example,
Accesses Constructor of Abstract Classes
An abstract class can have constructors like the regular class. And,
we can access the constructor of an abstract class from the
subclass using the super keyword. For example,
Here, we have used the super() inside
the constructor of Dog to access the
constructor of the Animal.
Note that the super should always be
the first statement of the subclass
constructor.
Java Abstraction
• Abstraction is an important concept of
object-oriented programming that
allows us to hide unnecessary details
and only show the needed
information.
• This allows us to manage complexity
by omitting or hiding details with a
simpler, higher-level idea.
Key Points to Remember
•We use the abstract keyword to create abstract classes and methods.
•An abstract method doesn't have any implementation (method body).
•A class containing abstract methods should also be abstract.
•We cannot create objects of an abstract class.
•To implement features of an abstract class, we inherit subclasses from it and create
objects of the subclass.
•A subclass must override all abstract methods of an abstract class. However, if the
subclass is declared abstract, it's not mandatory to override abstract methods.
•We can access the static attributes and methods of an abstract class using the
reference of the abstract class. For example,
Interface
An interface is a fully abstract class. It includes a group of abstract
methods (methods without a body).
We use the interface keyword to create an interface in Java. For example,
Implementing an Interface
Like abstract classes, we cannot create objects of interfaces.
To use an interface, other classes must implement it. We use the implements keyword
to implement an interface.
Implementing Multiple Interfaces
Extending an Interface
Advantages of Interface in Java
• Similar to abstract classes, interfaces help us to achieve abstraction in Java.
• Interfaces provide specifications that a class (which implements it) must follow.
• Interfaces are also used to achieve multiple inheritance in Java. For example,
default methods in Java Interfaces
• If a large number of classes were implementing this interface,
we need to track all these classes and make changes to them.
This is not only tedious but error-prone as well.
• To resolve this, Java introduced default methods. Default
methods are inherited like ordinary methods.
private and static Methods in Interface
• The Java 8 also added another feature to include static
methods inside an interface.
• With the release of Java 9, private methods are also supported
in interfaces.
We cannot create objects of an interface.
Learning
Slide Resource
https://www.programiz.com/java-programming/

More Related Content

PPT
ABSTRACT CLASSES AND INTERFACES.ppt
PDF
Java abstract Keyword.pdf
PPTX
06_OOVP.pptx object oriented and visual programming
PPTX
Abstraction in java.pptx
PPT
Java interfaces & abstract classes
PDF
Abstraction in Java: Abstract class and Interfaces
PPTX
Abstraction in java [abstract classes and Interfaces
PPTX
More oop in java
ABSTRACT CLASSES AND INTERFACES.ppt
Java abstract Keyword.pdf
06_OOVP.pptx object oriented and visual programming
Abstraction in java.pptx
Java interfaces & abstract classes
Abstraction in Java: Abstract class and Interfaces
Abstraction in java [abstract classes and Interfaces
More oop in java

Similar to Abstract Class and Interface for Java Intoductory course.pptx (20)

PDF
java-06inheritance
DOCX
Core java notes with examples
PDF
Advanced Programming _Abstract Classes vs Interfaces (Java)
PDF
Java OOP Programming language (Part 6) - Abstract Class & Interface
PPTX
abstract,final,interface (1).pptx upload
PDF
Abstract classes and Methods in java
PPTX
it is about the abstract classes in java
PPTX
Abstract Class In Java | Java Abstract Class Tutorial | Java Tutorial For Beg...
PPTX
When to use abstract class and methods in java
PPTX
Lecture-on-Object-Oriented-Programming-Language-Java.pptx
PPTX
Lecture 18
PPT
OOPS_AbstractClasses_explained__java.ppt
PDF
Exception handling and packages.pdf
PPT
Chapter 9 Interface
PPTX
Abstraction encapsulation inheritance polymorphism
PDF
Java 06
PPT
Abstract class
PPT
Abstract class
PPT
Abstract class
java-06inheritance
Core java notes with examples
Advanced Programming _Abstract Classes vs Interfaces (Java)
Java OOP Programming language (Part 6) - Abstract Class & Interface
abstract,final,interface (1).pptx upload
Abstract classes and Methods in java
it is about the abstract classes in java
Abstract Class In Java | Java Abstract Class Tutorial | Java Tutorial For Beg...
When to use abstract class and methods in java
Lecture-on-Object-Oriented-Programming-Language-Java.pptx
Lecture 18
OOPS_AbstractClasses_explained__java.ppt
Exception handling and packages.pdf
Chapter 9 Interface
Abstraction encapsulation inheritance polymorphism
Java 06
Abstract class
Abstract class
Abstract class
Ad

Recently uploaded (20)

PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Empathic Computing: Creating Shared Understanding
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
1. Introduction to Computer Programming.pptx
PPTX
Tartificialntelligence_presentation.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
A comparative analysis of optical character recognition models for extracting...
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
Getting Started with Data Integration: FME Form 101
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Spectral efficient network and resource selection model in 5G networks
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Empathic Computing: Creating Shared Understanding
“AI and Expert System Decision Support & Business Intelligence Systems”
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Accuracy of neural networks in brain wave diagnosis of schizophrenia
The Rise and Fall of 3GPP – Time for a Sabbatical?
Mobile App Security Testing_ A Comprehensive Guide.pdf
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
1. Introduction to Computer Programming.pptx
Tartificialntelligence_presentation.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
Digital-Transformation-Roadmap-for-Companies.pptx
Per capita expenditure prediction using model stacking based on satellite ima...
A comparative analysis of optical character recognition models for extracting...
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
SOPHOS-XG Firewall Administrator PPT.pptx
Getting Started with Data Integration: FME Form 101
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Ad

Abstract Class and Interface for Java Intoductory course.pptx

  • 1. Abstract Class Class Objectives: Why abstract class? How to Implement it? “Don’t be Hidden”
  • 2. Java Abstract Class The abstract class in Java cannot be instantiated (we cannot create objects of abstract classes). We use the abstract keyword to declare an abstract class. For example,
  • 3. An abstract class can have both the regular methods and abstract methods. For example,
  • 4. Java Abstract Method A method that doesn't have its body is known as an abstract method. We use the same abstract keyword to create abstract methods. For example, If a class contains an abstract method, then the class should be declared abstract. Otherwise, it will generate an error. For example,
  • 5. Java Abstract Class and Method Though abstract classes cannot be instantiated, we can create subclasses from it. We can then access members of the abstract class using the object of the subclass. For example,
  • 6. Implementing Abstract Methods If the abstract class includes any abstract method, then all the child classes inherited from the abstract superclass must provide the implementation of the abstract method. For example,
  • 7. Accesses Constructor of Abstract Classes An abstract class can have constructors like the regular class. And, we can access the constructor of an abstract class from the subclass using the super keyword. For example, Here, we have used the super() inside the constructor of Dog to access the constructor of the Animal. Note that the super should always be the first statement of the subclass constructor.
  • 8. Java Abstraction • Abstraction is an important concept of object-oriented programming that allows us to hide unnecessary details and only show the needed information. • This allows us to manage complexity by omitting or hiding details with a simpler, higher-level idea.
  • 9. Key Points to Remember •We use the abstract keyword to create abstract classes and methods. •An abstract method doesn't have any implementation (method body). •A class containing abstract methods should also be abstract. •We cannot create objects of an abstract class. •To implement features of an abstract class, we inherit subclasses from it and create objects of the subclass. •A subclass must override all abstract methods of an abstract class. However, if the subclass is declared abstract, it's not mandatory to override abstract methods. •We can access the static attributes and methods of an abstract class using the reference of the abstract class. For example,
  • 10. Interface An interface is a fully abstract class. It includes a group of abstract methods (methods without a body). We use the interface keyword to create an interface in Java. For example,
  • 11. Implementing an Interface Like abstract classes, we cannot create objects of interfaces. To use an interface, other classes must implement it. We use the implements keyword to implement an interface.
  • 13. Advantages of Interface in Java • Similar to abstract classes, interfaces help us to achieve abstraction in Java. • Interfaces provide specifications that a class (which implements it) must follow. • Interfaces are also used to achieve multiple inheritance in Java. For example,
  • 14. default methods in Java Interfaces • If a large number of classes were implementing this interface, we need to track all these classes and make changes to them. This is not only tedious but error-prone as well. • To resolve this, Java introduced default methods. Default methods are inherited like ordinary methods.
  • 15. private and static Methods in Interface • The Java 8 also added another feature to include static methods inside an interface. • With the release of Java 9, private methods are also supported in interfaces. We cannot create objects of an interface.