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:
private
public
protected
You can read more about them in this article
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