Java supports inheritance as its core functionality and then to achieve a lot of OOPs principles like abstraction using inheritance.
A class can extend another class using extends keyword and can inherit from an interface using implements keywords.
The access modifiers define rules for the member variables and methods of a class about their access from other classes (or anywhere in the code).
There are four access modifiers:
privatepublicprotectedYou can read more about them here
These concepts are very similar and are often confused.
interface Animal() {
public void bark();
}
class Dog implements Animal {
public void bark() {
System.out.println("Bark");
}
}
Here, Dog IS-A Animal
interface Engine {
}
class Car {
private Engine engine;
}
Here, Car HAS-A Engine