Explain the difference between abstract class and interfaces with an example for each.
Explain the difference between abstract class and interfaces with an example for each.
The differences between abstract class and interface are as follows:Abstract Class | Interface |
Can have abstract methods and concrete methods | Can have only method signatures and static final members |
All methods are not by default public | All methods by default abstract and public |
An abstract class can extend another abstract class | An interface can extend another interface but not a class |
The extended class can override the methods of its super class and its hierarchy | An implementing class can implement multiple interfaces |
All abstract methods must have abstract access modifier | All methods in an interface must not have abstract access modifier |
abstract class Shape
{
abstract void area();
abstract void perimeter();
void someMethod() // concrete method
{
..
}
}
interface Shape
{
void area();
void perimeter();
}
// amazon ebay shopbob.com hotels.com canon newegg.com
Comments
Post a Comment