Advertisement



< Prev
Next >



Abstract Class in Java





An abstract class is declared with the abstract keyword. Unlike a regular java class, an abstract class may not only contain regular methods(non-abstract), which are defined with curly braces { } but may also contain abstract methods, which end with a semicolon; or a mix of regular and abstract methods.






What are abstract methods?


Abstract methods are not implemented in the abstract class and are declared with -: Please remember, the internal logic of an abstract method is not provided, which means that an abstract method is not defined within a pair of curly braces {} and it ends with a semicolon ;






An example of an abstract method -
abstract public void add();

We have declared a method add with an abstract keyword, which makes it an abstract method. This method has a public access modifier and a void return-type, which means that this abstract method will not return any value. And as it should be, this abstract method ends with a semicolon ;

Note : An abstract method should never be declared with a private access modifier because doing so will make this abstract method inaccessible to the concrete class that extends the abstract class and wants to provide an implementation of its abstract method.


Advertisement




Some very important points about an abstract class.



//Java - Example of abstract class

interface A
{
void a();
void a_show();
}

abstract class B implements A
{
}

An abstract class has implemented an interface without implementing any of the methods of an interface.



Please share this article -





< Prev
Next >
< Class Member Access Modifiers
Interface >



Advertisement

Please Subscribe

Please subscribe to our social media channels for daily updates.


Decodejava Facebook Page  DecodeJava Twitter Page Decodejava Google+ Page




Advertisement



Notifications



Please check our latest addition

C#, PYTHON and DJANGO


Advertisement