Abstract classes are meant not be instantiated directly but are meant to be extended. Once a concrete class extends the abstract class, it has to provide implementation of the abstract methods of the abstract super class. But an abstract class can also have non-abstract methods. Abstract methods are fine since their implementation shall be provided by sub class, but what is the purpose of non-abstract methods in an abstract class.

Well their purpose is to be inherited and if required be overridden too. When we are using an abstract class, we are creating inheritance relationship between the two classes. (i.e. abstract class and its sub class). The following source code shows how the abstract and non-abstract methods of a class can be used:

public abstract class GenericBank{
    private double balance;
    public abstract boolean openAccount(){}
    pubic double getBalance{
        return balance;
    }
}

public class NewBank extends GenericBank {
    public boolean openAccount(){
        .......
        .......
    }
}

public class Test{
    public static void main(String[] args){
        GenericAccount ga = new NewBank();
        ga.openAccount();
        .......
        .......
        ga.getBalance();
    }
}

Thus we can see that the getBalance method has been invoked on an instance of MyBank and this method was inherited from the super class named GenericBank.

Methods of an Abstract class admin Core Java
Abstract classes are meant not be instantiated directly but are meant to be extended. Once a concrete class extends the abstract class, it has to provide implementation of the abstract methods of the abstract super class. But an abstract class can also have non-abstract methods. Abstract methods are fine...
<p>Abstract classes are meant not be instantiated directly but are meant to be extended. Once a concrete class extends the abstract class, it has to provide implementation of the abstract methods of the abstract super class. But an abstract class can also have non-abstract methods. Abstract methods are fine since their implementation shall be provided by sub class, but what is the purpose of non-abstract methods in an abstract class. Well their purpose is to be inherited and if required be overridden too. When we are using an abstract class, we are creating inheritance relationship between the two classes. (i.e. abstract class and its sub class). The following source code shows how the abstract and non-abstract methods of a class can be used:</p> 1 <p>Thus we can see that the getBalance method has been invoked on an instance of MyBank and this method was inherited from the super class named GenericBank.</p>
The following two tabs change content below.
I run this blog with lots of passion. In this website, you will find tutorials on Core Java, Spring, Struts, Web Applications, Portals and Database. Please support me and the website by sharing the posts on your facebook / twitter. You can tap the share button at the top of each post. Thanks for the support.