which of the keywords are used to archive inheritance in java
Answers
Answer:
Java static keywords are used.............
Answer:
extends and implements
extends keyword
In Java, we can inherit the fields and methods of a class by extending it using extends keyword. Please note that in Java, a class can extend maximum one class only.
Take the example of ArrayList class. It extends AbstractList class which in turn extends AbstractCollection class.
So essentially ArrayList class has methods and behaviors of both it’s parent classes AbstractList and AbstractCollection.
AbstractCollection provides methods like contains(Object o), toArray(), remove(Object o) etc.
While AbstractList class provides add(), indexOf(), lastIndexOf(), clear() etc. Some of the methods are overridden by ArrayList again.
implements :
Interfaces are way to enforce a contract in Java. They force the implementing class to provide a certain behavior. To implement an interface, class must use implements keyword.
In Java, we can implement more than one interfaces. In this case, class must implement all the methods from all the interfaces. (or declare itself abstract).
Look at the ArrayList class declaration one more time. It implements 4 interfaces i.e. List, RandomAccess, Cloneable and Serializable. It has implemented all the methods in given interfaces.