What do you understand with Abstract class in Java?

18:19

For Abstract class you should have knowledge of Abstract methods in java. An Abstract method is nothing but a simple method in java but without body or say it doesn’t have statements into it. It only contains the declaration of method 
i.e. having modifier, return type, name and parameters.
So, now we can say the class having Abstract methods should be declared as Abstract and so it is called Abstract class.
An Abstract class is never instantiated or we can say we cannot create object of Abstract class. Although it does not provide 100% abstraction because it can also have methods with definition.
Syntax :
abstract class class_name { }

Some properties of Abstract method:
Method that are declared without any body within an abstract class are called abstract method. The method body will be defined by its subclass. Abstract method can never be final and static. Any class that extends an abstract class must implement all the abstract methods declared by the super class.
Syntax :
abstract return_type function_name ();    //No definition

Example of Abstract class :
abstract class A
        {     
           abstract void callme();
        }
        class B extends A
        {
           void callme()
        {
            System.out.println("this is callme.");
        }
         public static void main(String[] args)
        {
            B b = new B();
             b.callme();
        }
        }

OUTPUT :
this is callme.

When to use Abstract Methods & Abstract Class?
Abstract methods are usually declared where two or more subclasses are expected to do a similar thing in different ways through different implementations. These subclasses extend the same Abstract class and provide different implementations for the abstract methods.
Abstract classes are used to define generic types of behaviors at the top of an object-oriented programming class hierarchy, and use its subclasses to provide implementation details of the abstract class.
Please Share with your friends to make them understand and feel us confident to write more for you.
Thank you.

You Might Also Like

0 comments

If you have any questions or suggestions, you are free to ask, i will appreciate that and, i will try my best...

Check Out