I know the fundamentals of OOP concepts[Inheritance, Abstraction, Encapsulation, Polymorphism]
We use Inheritance in case of Parent-Child relationship[Child can have all functionalities which Parent have and can add more functionality to itself too]
And we use Abstract class(In java) for a partial set of default implementations of methods in a class, which also can be implemented by simple Inheritance.
Look below example which makes my point clear.
Inheritance:
Parent class
public class Parent {
// This method will remain same for all child classes.No need to override
public void abc() {
System.out.println("Parent here");
}
// This methods need to be overridden from child class
public int getROI() {
return 0;
}
}
Child class
public class Child extends Parent{
@Override
public int getROI(){
return 5;
}
public static void main(String[] args) {
Child child =new Child();
child.abc();
System.out.println(child.getROI());
}
}
Abstract Class:
Parent class
abstract class Parent {
// This method will remain same for all child classes.No need to override
public void abc() {
System.out.println("Parent here");
}
// This methods need to be implemented from child class
public abstract int getROI();
}
Child class
public class Child extends Parent{
public int getROI(){
return 5;
}
public static void main(String[] args) {
Child child =new Child();
child.abc();
System.out.println(child.getROI());
}
}
For above programs o/p will be same.
O/P:
Parent here
5
So I think,
Inheritance: We need to override the method in child class
Abstract class: Put abstract keyword in method name and need to implement the method in child class
So Inheritance and abstract class is same regardless of abstract keyword
So we can implement abstract class using inheritance, here just method signature change classes(That's my belief).
Is there any significant difference?