A B S T R A C T I O N
SIT Internal
LEARNING OUTCOMES
• What is abstraction?
• Need
• Creating abstract classes and methods
• Rules and Restrictions
SIT Internal
W H AT I S A B ST R AC T I O N ?
• Hiding complex, low-level details with a simpler, high-level layer
• The process of hiding certain details and showing only essential
information to the user.
What does it mean?
SIT Internal
ABSTRACTION
simplified representations of objects
Abstract Abstract
Classes Methods
focus on what they do, rather than how they do it
SIT Internal
ABSTRACT CLASSES
• A class whose object cannot be created
• It can only be inherited
SIT Internal
ABSTRACT METHODS
• Methods whose signature has been provided, but no
implementation for that method is given
• Method without a meaningful or incomplete
implementation
abstract void setInfo();
SIT Internal
ABSTRACT METHODS
Any class which contains an abstract method MUST also be
abstract
abstract class Person{
abstract void setInfo();
}
SIT Internal
ABSTRACT METHODS
Contract: The Sub-class of the abstract class must implement all
abstract methods in parent
abstract class Person{
abstract void setInfo();
}
public class Student extends Person
public class Teacher extends Person {
{
void setInfo(){
void setInfo(){
}
}
}
}
SIT Internal
ABSTRACT METHODS
• An abstract class can extend abstract class A{
abstract void setValue();
another abstract class }
abstract class B extends A{
• Last sub-class should not be //some code
}
abstract
class C extends B
• The last sub-class MUST
{
implement remaining abstract void setValue() {
}
methods }
SIT Internal
ABSTRACT CLASSES
• Can include abstract and non-abstract (concrete) methods
• Abstract methods are declared without an implementation, while
concrete methods have actual code implementation.
SIT Internal
CONCLUSION
• Abstraction: lets you use objects in a way that hides the details you don't need to
know, making it easier to work with complex systems and allowing you to focus on
the important aspects of your code
• Abstract Classes:
– classes that cannot be instantiated directly
– serve as blueprints or templates for creating concrete (non-abstract) subclasses
• Abstract Methods:
– declared without a method body
– Subclasses must provide implementations for all abstract methods.