0% found this document useful (0 votes)
90 views24 pages

Abstract Classes and Methods

This document discusses abstraction in Java through abstract classes and methods. It defines abstraction as hiding implementation details while providing functionality to users. Abstract classes can contain both abstract and non-abstract methods, and must be declared with the "abstract" keyword. Abstract methods only have a declaration without a method body, while subclasses must implement all abstract methods or also be declared abstract. Abstract classes cannot be instantiated.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
90 views24 pages

Abstract Classes and Methods

This document discusses abstraction in Java through abstract classes and methods. It defines abstraction as hiding implementation details while providing functionality to users. Abstract classes can contain both abstract and non-abstract methods, and must be declared with the "abstract" keyword. Abstract methods only have a declaration without a method body, while subclasses must implement all abstract methods or also be declared abstract. Abstract classes cannot be instantiated.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 24

ABSTRACT CLASSES AND METHODS

BY GROUP 7
ABSTRACTION
Abstraction in java is a process of hiding
the implementation details from the user
such that only the functionality will be
provided to the user. Abstraction can be
achieved through two methods.
ABSTRACT CLASSES

INTERFACES
ABSTRACT CLASSES
Any class created in java is automatically declared
as concrete, therefore for a class to be abstract it
must be declared using the “Abstract” keyword. An
abstract class can have both abstract and non-
abstract methods.
N.B. Abstraction is one of the four major concepts behind OOP
An abstract class is declared as follows

access_modifier abstract class class_name{ }

access_modifier = public/private/default/protected
There are rules governing the use,
application and extension of abstract
classes. but first we need to talk about
extension.
EXTENSION
When a class is extended it is called the super class
and the class that extends it is the subclass

Extension of classes allows a subclass access to all


methods and variables in the super-class
regardless of the access modifier.
A line of code which shows an example of extension
ABSTRACT METHODS
In Abstract Methods, They are those methods
which have only declaration do not have definition.
Declaration means creating only the method
signature (the method name, parameters and
return type), but no method body, where as
definition means creating the method signature
and the method body as well.
This is what an abstract method looks like
in an abstract class
RULES FOR JAVA ABSTRACT
CLASSES AND METHODS
An abstract class may not have an abstract
method within it, but if even just a single
method in a class is abstract then the class
must be declared abstract
Any sub-class extending from an abstract
class should either implement all the
abstract methods of the super-class or the
sub-class itself should be marked as
abstract.
The abstract method should not have
method body. Even empty flower
braces{ } are not allowed.
Abstract classes are extended to other
classes whether abstract or not
ABSTRACT CLASSES CANNOT BE INSTANTIATED,
ABSTRACT CLASSES CAN HAVE FINAL
METHODS
ABSTRACTION VS
ENCAPSULATION
Abstraction is very similar to
encapsulation but they are different in
a way. Both of them have to do with
hiding.
Encapsulation is data hiding while
Abstraction is detail hiding
Encapsulation in Java is a mechanism for
wrapping the data and code action on the data
together as a single unit. It is used to hide what
should be hidden and make visible what is
intended to be visible.
In Encapsulation, the variables of a class will be
hidden from other classes and can be accessed
only through the methods of their current class
i.e getter and setter methods(accessor and
mutuation)
Abstraction on the other hand is the process of
hiding the implementation details from the user,
only the functionality will be provided to the user.
In other words the user have information on what
the object does instead of how it does it.

You might also like