difference between abstract class and interface

                      The abstract class and interface both are used to achieve abstraction in java, but using of interfaces we can achieve 100% abstraction.


Abstract class   

Interface

The abstract class have abstract methods and non-abstract methods and must use public abstract.
Interface can have only abstract methods. By default, every method is an abstract method.
For practical implementation, we are using abstract classes.  Ex: Http servlet
For future implementation we are using interfaces.
Ex: Servlets
An abstract class doesn’t support multiple inheritance.      
By using interface we can achieve multiple inheritance
In Abstract class local variables and static and final, class variables.
Interface have only final and static variables.
The abstract class has a main() method and we can’t create an object in the abstract class.
Interface doesn’t contain main() method and we can create a reference to the interface.
We can use transient variables in abstract class
In interface serialization concept can’t apply so transient can’t apply.
We can create constructor for abstract class
We can’t create constructor for interface.

Abstract keyword is used to declare abstract class
Interface keyword is used to create interface.
Only child classes can extend  the abstract class.
Any class can implement and extend the interface.
Ex:
public abstract class sample{
public abstract void eat();
}
Ex:
public interface fly{
void flyable();
}



1 comments:

titanium rings - Tinting - Tinting
Tinting งานออนไลน์ is an art form 2019 ford fusion hybrid titanium for ceramic rings. Tinting has two designs tube supplier that titanium for sale are known as rings and titanium white rocket league are made for bronze. The first are titanium rings,


EmoticonEmoticon