Skip to content
Menu
Code for Java c
  • Home
  • Java
    • Java Examples
    • Java tutorials
  • C
    • C tutorials
    • C Examples
  • C++
    • C++ Tutorials
    • C++ Examples
  • Python
    • Python Tutorials
    • Python Examples
  • About
    • About me
    • contact us
    • disclaimer
    • Privacy Policy
Code for Java c

Abstract class in Java programing language

Posted on February 24, 2017January 29, 2020

Abstract class in Java programing language

In this tutorial, we will discuss the OOP concept of abstract class in Java programing language.

Abstraction is one of the Oop concepts.  A class that contains at least one abstract method is known as an abstract class.

The abstract class is a class which contains at least one abstract method. That means the abstract method does not do any implementation, it just has a signature.

So abstract methods are methods that can be only declared, not defined.

The class becomes abstract if one or more of the methods are abstract.

We cannot create an object of an abstract class.

Sub class must provide an implementation for the abstract methods of the super class or themselves be declared as abstract.

What is the use of an abstract class?

Abstraction is a concept that hides implementation details and only presents the features to users.

Syntax of abstract class

abstract class A{
// abstract is a keyword
// abstract class have abstract and non-abstract methods
// implementation of abstract methods is out of the another class
// all abstract methods in abstract class must implement another class }


Syntex of the abstract method

abstract void method_name();

//no body and abstract
//only declare no define

Program 1

In the following example, Abstract1 is an abstract class and it has two methods inside the class

abstract void run() – it is an abstract method, it has no implementation

void print() – It is a normal method with implementation within the class

implementation of abstract method(void run()) is provided by the override class

Abstract class in Java programing language
Example
Understanding the real example of abstract class
In this example, an Animal is an abstract class. that contain only one abstract method myanimal() Its implementation is provided by the dog and cat classes.
Abstract class in Java programing language
Example

An abstract class can have properties as an abstract method, method, constructor, and even main() method

Abstract class in Java programing language
Example

Related Links

Encapsulation in C++                                       Encapsulation in Java

Polymorphism in C++                                      Methodoverriding in Java

Method overloading in java                             Constructor overloading in Java

Exception Handling in Java

 

Related

Recent Posts

  • Subtract two numbers using method overriding
  • PHP Star triangle Pattern program
  • Using function or method to Write temperature conversion : Fahrenheit into Celsius
  • Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user
  • Write temperature conversion program: Fahrenheit into Celsius
  • How to write a program to convert Fahrenheit into Celsius

tag

Addition (6) Array (38) C++ language (91) C language (98) c sharp (23) Division (6) Function (29) if else (32) Java language (102) JavaScript (5) loops (137) Multiply (7) Oop (2) patterns (65) PHP (13) Python Language (38) Subtraction (7) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2025 Code for Java c | Powered by SuperbThemes