Abstract Class in Java:
An abstract class is a class that is declared as abstract. It may or may not include abstract methods. Abstract classes cannot be instantiated, but they may be a subclass.Abstract class in Java is used to declare functionality that is implemented by one or more subclasses. Abstract classes cannot be instantiated (if a class is declared as abstract, no object of that class can be created). To declare a class abstract, use the abstract keyword in front of the class keyword at the beginning of the class declaration.
The general format is:
{
//
-----------------
-----------------
}
Here,
Here is a simple example of a class with an abstract method:
{
}
In the above example, the class students declare one abstract method called numstudents (). Therefore, the class itself must also be declared abstract.
Abstract Methods:
An abstract method is a method that should be defined in the derived class. The method in an abstract class often has empty bodies. When the keyword abstract is prefixed before a method declaration, it becomes abstract.To declare an abstract method as follows:
Note: The method in an abstract class often has empty bodies.
Sample Program:
{
}
{
{
}
}
{
{
}
}
{
{
System
System
}
}
The output of sample example of abstract class in Java is:
38
42
Explanation of sample example of abstract class in Java is:
In the above example, the class students declare one abstract method named numstudentsI hope you guys understand what is abstract class in Java in brief. If you guys have any queries or you guys have any suggestion how do I improve my blog please comment me below.
Reccommended post:
- Super keyword in Java
- Overriding method in Java
- Inheritance in Java
- StringBuffer class in Java
- Inner classes in Java
- Static and fixed method in Java