SlideShare a Scribd company logo
1 of 43
Object Oriented
Visual Programming
ABSTRACTION
ABSTRACTION
▰ Abstraction is one of the key concepts of object-oriented
programming (OOP) languages.
▰ Its main goal is to handle complexity by hiding unnecessary
details from the user. That enables the user to implement more
complex logic on top of the provided abstraction without
understanding or even thinking about all the hidden complexity.
▰ In Java programming, abstraction is achieved using Abstract
classes and interfaces.
WHAT IS ABSTRACTIONS?
▰ Abstraction refers to the act of representing essential features without including the
background details or explanations.
▰ Abstraction lets you focus on what the object does instead of how it does it.
▰ Therefore, it is an art to simplify things from outsiders.
▰ The abstraction in Java can be achieved by:
▻ Abstract Class : partial or total abstraction
▻ Interface : total abstraction
▰ Since classes use the concept of data abstraction, they are known as Abstract Data Types
(ADT).
WHY ABSTRACTIONS?
▰ easier to think about - hide what doesn't matter
▰ protection - prevent access to things you shouldn't see
▰ plug compatibility
▻ replacement of pieces, often without recompilation,
definitely without rewriting libraries
▻ division of labor in software projects
Abstraction vs Encapsulation
▰ Abstraction = Implementation Hiding.
hiding the details and implementation of the code from
outside world.
▰ Encapsulation = Information Hiding.
hiding the hiding the data and controlling the visibility of the
code.
Abstract Classes
▰ A class declared as abstract is known as abstract class.
▰ An abstract class must be declared with an abstract keyword.
▰ It cannot be instantiated.
▰ It needs to be extended to be used.
▰ It must contain at least 1 abstract method declaration.
▰ It may contain constructors, non-abstract, static and/or final
methods as well. Otherwise, fully abstraction concept will be
achieved.
Declaring an Abstract Class
▰ To declare an abstract class, you simply use the abstract keyword
before the class keyword.
Declaring an Abstract Class
▰ To declare an abstract class, you simply use the abstract keyword
before the class keyword. Here’s a basic example:
In this code snippet, we’ve declared an abstract class Vehicle with an abstract
method run(). This method doesn’t have a body – it’s just a declaration. That’s
because the implementation of this method is provided by the class that extends
this abstract class
Syntax of Abstract Method
▰ The syntax for the abstract method is similar to any user-defined
method in Java except you have to add abstract keyword at the
start of the declaration.
▰ For example
Abstract Class in Java
To make an abstract class, you must declare a class with an abstract
keyword.
An abstract class may have a mixed set of abstract and regular(non-abstract)
methods.
Abstract Class in Java
When a regular class extends an abstract class, it must implement
the abstract methods of an abstract class, or a compile error is
issued.
Abstract Class in Java
You can even create an abstract class which only contains concrete
regular methods and no abstract methods.
Abstract Class in Java
You must declare a class with the abstract keyword, even when there
is only a single abstract method in it.
Abstract Class in Java
Abstract Class in Java
Example
This example creates an abstract class
called "Shapes"
This example creates an abstract class Animal with abstract
methods eat() and sleep(). Create subclasses Lion, Tiger, and
Deer that extend the Animal class and implement the eat() and
sleep() methods differently based on their specific behavior.
Abstract Class in Java
Example
▰ In this program, the Animal class is an abstract class that
defines the abstract methods eat() and sleep().
▰ The Lion, Tiger, and Deer classes extend the Animal class and
provide their own implementations for the eat() and sleep()
methods based on their specific behavior.
▰ The Main class demonstrates the usage of these classes by
creating objects of each subclass and invoking the eat() and
sleep() methods accordingly.
INTERFACE
▰ An interface is a 100% abstract class which is declared with
the interface keyword. Methods of an interface are implicitly
abstract, hence when declaring an interface, you must not
provide an implementation of any of its methods and its
methods should end with a semicolon ;
▰ Interface methods are implicitly declared with the public access
modifier and abstract keyword, which means that even if you
don't explicitly type public and abstract with interface methods,
they are still always public and abstract, by default.
INTERFACE
▰ A class can implement an
interface by providing the
internal logic of all methods of
an interface, conforming to
each of their method
signatures. To implement an
interface, a class must use the
implements keyword.
INTERFACE
▰ You cannot instantiate or create an object of an interface, because it is a 100%
abstract and skeletal. Hence, instantiating an interface gives a compile error.
INTERFACE
▰ A class can
implement multiple
interfaces and it
must provide an
implementation of
all their methods.
INTERFACE
▰ An abstract class
can implement
an interface and
it doesn't have to
implement its
methods.
INTERFACE
ABSTRACT VS INTERFACE
This example create an interface Shape with the getArea()
method. Create three classes Rectangle, Circle, and Triangle that
implement the Shape interface. Implement the getArea() method
for each of the three classes.
Interface in Java Example
Exercises
▰ Write a Java program to create an abstract class Shape3D with
abstract methods calculateVolume() and
calculateSurfaceArea(). Create subclasses Sphere and Cube
that extend the Shape3D class and implement the respective
methods to calculate the volume and surface area of each
shape.

More Related Content

Similar to 06_OOVP.pptx object oriented and visual programming

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
 
Abstract class and interface
Abstract class and interfaceAbstract class and interface
Abstract class and interfaceMazharul Sabbir
 
When to use abstract class and methods in java
When to use abstract class and methods in java When to use abstract class and methods in java
When to use abstract class and methods in java kritikumar16
 
Abstraction in java.pptx
Abstraction in java.pptxAbstraction in java.pptx
Abstraction in java.pptxAsifMulani17
 
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
 
Abstract Class Presentation
Abstract Class PresentationAbstract Class Presentation
Abstract Class Presentationtigerwarn
 
Abstract Class Presentation
Abstract Class PresentationAbstract Class Presentation
Abstract Class Presentationtigerwarn
 
OOFeatures_revised-2.pptx
OOFeatures_revised-2.pptxOOFeatures_revised-2.pptx
OOFeatures_revised-2.pptxssuser84e52e
 
Core java notes with examples
Core java notes with examplesCore java notes with examples
Core java notes with examplesbindur87
 
Abstract_descrption
Abstract_descrptionAbstract_descrption
Abstract_descrptionMahi Mca
 
What are Abstract Classes in Java | Edureka
What are Abstract Classes in Java | EdurekaWhat are Abstract Classes in Java | Edureka
What are Abstract Classes in Java | EdurekaEdureka!
 
More oop in java
More oop in javaMore oop in java
More oop in javaSAGARDAVE29
 
Abstract Class In Java | Java Abstract Class Tutorial | Java Tutorial For Beg...
Abstract Class In Java | Java Abstract Class Tutorial | Java Tutorial For Beg...Abstract Class In Java | Java Abstract Class Tutorial | Java Tutorial For Beg...
Abstract Class In Java | Java Abstract Class Tutorial | Java Tutorial For Beg...Simplilearn
 
ch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdf
ch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdfch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdf
ch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdfbca23189c
 
WHAT IS ABSTRACTION IN JAVA
WHAT IS ABSTRACTION IN JAVAWHAT IS ABSTRACTION IN JAVA
WHAT IS ABSTRACTION IN JAVAsivasundari6
 
WHAT IS ABSTRACTION IN JAVA
WHAT IS ABSTRACTION IN JAVAWHAT IS ABSTRACTION IN JAVA
WHAT IS ABSTRACTION IN JAVAsivasundari6
 

Similar to 06_OOVP.pptx object oriented and visual programming (20)

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)
 
Abstract class and interface
Abstract class and interfaceAbstract class and interface
Abstract class and interface
 
When to use abstract class and methods in java
When to use abstract class and methods in java When to use abstract class and methods in java
When to use abstract class and methods in java
 
Abstraction in java.pptx
Abstraction in java.pptxAbstraction in java.pptx
Abstraction in java.pptx
 
Interfaces in java
Interfaces in javaInterfaces in java
Interfaces in java
 
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
 
Abstract Class Presentation
Abstract Class PresentationAbstract Class Presentation
Abstract Class Presentation
 
Abstract Class Presentation
Abstract Class PresentationAbstract Class Presentation
Abstract Class Presentation
 
OOFeatures_revised-2.pptx
OOFeatures_revised-2.pptxOOFeatures_revised-2.pptx
OOFeatures_revised-2.pptx
 
Core java notes with examples
Core java notes with examplesCore java notes with examples
Core java notes with examples
 
Abstract_descrption
Abstract_descrptionAbstract_descrption
Abstract_descrption
 
JAVA PPT -3 BY ADI.pdf
JAVA PPT -3 BY ADI.pdfJAVA PPT -3 BY ADI.pdf
JAVA PPT -3 BY ADI.pdf
 
What are Abstract Classes in Java | Edureka
What are Abstract Classes in Java | EdurekaWhat are Abstract Classes in Java | Edureka
What are Abstract Classes in Java | Edureka
 
More oop in java
More oop in javaMore oop in java
More oop in java
 
Abstract Class In Java | Java Abstract Class Tutorial | Java Tutorial For Beg...
Abstract Class In Java | Java Abstract Class Tutorial | Java Tutorial For Beg...Abstract Class In Java | Java Abstract Class Tutorial | Java Tutorial For Beg...
Abstract Class In Java | Java Abstract Class Tutorial | Java Tutorial For Beg...
 
ch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdf
ch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdfch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdf
ch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdf
 
Java interfaces
Java   interfacesJava   interfaces
Java interfaces
 
Java basics
Java basicsJava basics
Java basics
 
WHAT IS ABSTRACTION IN JAVA
WHAT IS ABSTRACTION IN JAVAWHAT IS ABSTRACTION IN JAVA
WHAT IS ABSTRACTION IN JAVA
 
WHAT IS ABSTRACTION IN JAVA
WHAT IS ABSTRACTION IN JAVAWHAT IS ABSTRACTION IN JAVA
WHAT IS ABSTRACTION IN JAVA
 

Recently uploaded

High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...Call Girls in Nagpur High Profile
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAbhinavSharma374939
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 

Recently uploaded (20)

High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog Converter
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 

06_OOVP.pptx object oriented and visual programming

  • 2. ABSTRACTION ▰ Abstraction is one of the key concepts of object-oriented programming (OOP) languages. ▰ Its main goal is to handle complexity by hiding unnecessary details from the user. That enables the user to implement more complex logic on top of the provided abstraction without understanding or even thinking about all the hidden complexity. ▰ In Java programming, abstraction is achieved using Abstract classes and interfaces.
  • 3. WHAT IS ABSTRACTIONS? ▰ Abstraction refers to the act of representing essential features without including the background details or explanations. ▰ Abstraction lets you focus on what the object does instead of how it does it. ▰ Therefore, it is an art to simplify things from outsiders. ▰ The abstraction in Java can be achieved by: ▻ Abstract Class : partial or total abstraction ▻ Interface : total abstraction ▰ Since classes use the concept of data abstraction, they are known as Abstract Data Types (ADT).
  • 4. WHY ABSTRACTIONS? ▰ easier to think about - hide what doesn't matter ▰ protection - prevent access to things you shouldn't see ▰ plug compatibility ▻ replacement of pieces, often without recompilation, definitely without rewriting libraries ▻ division of labor in software projects
  • 5. Abstraction vs Encapsulation ▰ Abstraction = Implementation Hiding. hiding the details and implementation of the code from outside world. ▰ Encapsulation = Information Hiding. hiding the hiding the data and controlling the visibility of the code.
  • 6. Abstract Classes ▰ A class declared as abstract is known as abstract class. ▰ An abstract class must be declared with an abstract keyword. ▰ It cannot be instantiated. ▰ It needs to be extended to be used. ▰ It must contain at least 1 abstract method declaration. ▰ It may contain constructors, non-abstract, static and/or final methods as well. Otherwise, fully abstraction concept will be achieved.
  • 7. Declaring an Abstract Class ▰ To declare an abstract class, you simply use the abstract keyword before the class keyword.
  • 8. Declaring an Abstract Class ▰ To declare an abstract class, you simply use the abstract keyword before the class keyword. Here’s a basic example: In this code snippet, we’ve declared an abstract class Vehicle with an abstract method run(). This method doesn’t have a body – it’s just a declaration. That’s because the implementation of this method is provided by the class that extends this abstract class
  • 9. Syntax of Abstract Method ▰ The syntax for the abstract method is similar to any user-defined method in Java except you have to add abstract keyword at the start of the declaration. ▰ For example
  • 10. Abstract Class in Java To make an abstract class, you must declare a class with an abstract keyword.
  • 11. An abstract class may have a mixed set of abstract and regular(non-abstract) methods. Abstract Class in Java
  • 12. When a regular class extends an abstract class, it must implement the abstract methods of an abstract class, or a compile error is issued. Abstract Class in Java
  • 13. You can even create an abstract class which only contains concrete regular methods and no abstract methods. Abstract Class in Java
  • 14. You must declare a class with the abstract keyword, even when there is only a single abstract method in it. Abstract Class in Java
  • 15. Abstract Class in Java Example This example creates an abstract class called "Shapes"
  • 16.
  • 17.
  • 18.
  • 19. This example creates an abstract class Animal with abstract methods eat() and sleep(). Create subclasses Lion, Tiger, and Deer that extend the Animal class and implement the eat() and sleep() methods differently based on their specific behavior. Abstract Class in Java Example
  • 20. ▰ In this program, the Animal class is an abstract class that defines the abstract methods eat() and sleep(). ▰ The Lion, Tiger, and Deer classes extend the Animal class and provide their own implementations for the eat() and sleep() methods based on their specific behavior. ▰ The Main class demonstrates the usage of these classes by creating objects of each subclass and invoking the eat() and sleep() methods accordingly.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27. INTERFACE ▰ An interface is a 100% abstract class which is declared with the interface keyword. Methods of an interface are implicitly abstract, hence when declaring an interface, you must not provide an implementation of any of its methods and its methods should end with a semicolon ;
  • 28. ▰ Interface methods are implicitly declared with the public access modifier and abstract keyword, which means that even if you don't explicitly type public and abstract with interface methods, they are still always public and abstract, by default. INTERFACE
  • 29. ▰ A class can implement an interface by providing the internal logic of all methods of an interface, conforming to each of their method signatures. To implement an interface, a class must use the implements keyword. INTERFACE
  • 30. ▰ You cannot instantiate or create an object of an interface, because it is a 100% abstract and skeletal. Hence, instantiating an interface gives a compile error. INTERFACE
  • 31. ▰ A class can implement multiple interfaces and it must provide an implementation of all their methods. INTERFACE
  • 32. ▰ An abstract class can implement an interface and it doesn't have to implement its methods. INTERFACE
  • 34. This example create an interface Shape with the getArea() method. Create three classes Rectangle, Circle, and Triangle that implement the Shape interface. Implement the getArea() method for each of the three classes. Interface in Java Example
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43. Exercises ▰ Write a Java program to create an abstract class Shape3D with abstract methods calculateVolume() and calculateSurfaceArea(). Create subclasses Sphere and Cube that extend the Shape3D class and implement the respective methods to calculate the volume and surface area of each shape.