A class that is missing definitions for one or more methods. You can’t thus create an object of that class. You must first create a subclass and provide definitions for the abstract methods. Unlike interfaces, abstract classes may implement some of the methods. Though you can’t instantiate an abstract class, you can invoke its static methods.
An abstract class cannot instantiated in other words nobody can ever make a new instance of that class . you can still use that abstract class as a declared reference type,for the purpose of polymorphism.
Abstract Methods:

● Methods that do not have implementation (body)

● T0 create an abstract method, just write the methoddeclaration without the body and use the abstractkeyword– No { }

● For example,
// Note that there is no bodypublic abstract void someMethod();

An abstract class has no use ,no value and no purpose unless it it extended.
The reason for using first of all abstract class or interface insted of simple class is to provide “Reusability” i.e. we can use the same interface or abstract class for more than one classes without making any changes in the body of the abstract class or interface. As by using the concept of Inheritance in Java, we use both of them by:
1. Extending the Abstract Class &

2. Implementing the interface
Now, in case of Abstract class, we declare one or more method of that class as “abstract” and all those methods we need to override in the class where we are extending the abstract class. But one limitation still remains here that we can not extend more than one class at a time for a single class i.e. we can not have the functionality of more than one class in the single class at a time.
To overcome this, for providing multiple inheritance concept, we use “Interface“. It is possible to implement more than once interface in one class. Just we need is to override all the methods declared in the interface in the class where we are implementing the interface because when we create an interface, the methods declared in it implicitly becomes Abstract and Final.
Ex:

public class AppletDemo implements ActionListener, FocusListener{

}
In the above example, we are implementing two interfaces ActionListener and FocusListener at the same time in one class.
So, ultimate goal of using both abstract class and interface concept is to have Reusability of any kind of function that we want to provide to any of the class.

Advertisements