< Prev
Next >



Abstract Class in Java





Abstract class is a class that is declared with the abstract keyword. Unlike a simple java class, an abstract class may not only contain the regular methods(defined with curly braces { }) but may also contain the abstract methods(ending 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 they are declared with -: And the internal logic of an abstract method is not provided i.e. abstract methods are not defined with a curly braces {} but they rather end 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), having a public access modifier and a void return-type, which means 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 implementation of this abstract method(within the abstract class).




Some very important points about an abstract class.



interface A
{
void a();
}

abstract class B implements A
{
}

An abstract class can even implement an interface without implementing any of interface's methods.



Please share this article -

Facebook Google Pinterest Reddit Tumblr Twitter




< Prev
Next >
< Class Member Access Modifiers
Interface >

Please Subscribe

Please subscribe to our social media channels for daily updates.


Decodejava Facebook Page  DecodeJava Twitter Page Decodejava Google+ Page

Notifications



COMING SOON
-
PYTHON