In the vast landscape of object-oriented programming, Java offers a robust set of tools for class inheritance. Understanding the keywords used to inherit a class in Java is fundamental to leveraging the power of inheritance for code reusability and polymorphism. Let's delve into the key keywords: extends, implements, and their nuances.

Inheritance in Java allows one class to acquire the properties and methods of another. This relationship is established using the keywords extends and implements. Before we dive into these, let's briefly discuss the concept of interfaces, which play a crucial role in Java's inheritance model.

Inheritance in Java
Inheritance in Java is primarily achieved using the extends keyword. When a class extends another, it inherits all the non-private fields and methods of the parent class. This includes both instance variables and methods.

However, it's important to note that a class can only extend one other class (single inheritance). This is where interfaces come into play, allowing a class to implement multiple interfaces, thereby achieving a form of multiple inheritance.
Extends Keyword

The extends keyword is used to create a subclass (or derived class) from a superclass (or base class). The subclass inherits all the non-private fields and methods of the superclass. Here's a simple example:
```java public class Animal { public void eat() { System.out.println("Eating"); } } public class Dog extends Animal { public void bark() { System.out.println("Barking"); } } ```
In this example, the Dog class extends the Animal class, inheriting the eat method.
Implements Keyword

The implements keyword is used to implement interfaces. An interface is a completely abstract class that contains only abstract methods (no method bodies). A class can implement multiple interfaces, providing a way to achieve multiple inheritance in Java.
When a class implements an interface, it must provide implementations for all the methods declared in the interface. Here's an example:
```java public interface Flyable { void fly(); } public class Bird implements Flyable { public void fly() { System.out.println("Flying"); } } ```
In this example, the Bird class implements the Flyable interface, providing an implementation for the fly method.

Inheritance vs. Implementation
While both extends and implements are used for inheritance, they serve different purposes. The extends keyword is used for class inheritance, while the implements keyword is used for interface implementation.




















Moreover, a class can only extend one other class, but it can implement multiple interfaces. This allows for a more flexible and powerful inheritance model in Java.
Inherits Keyword (Deprecated)
Java also had a third keyword, inherits, which was used in earlier versions for class inheritance. However, this keyword is now deprecated and its use is strongly discouraged. The recommended way to achieve inheritance is by using the extends keyword.
Here's an example of the deprecated usage:
```java public class Animal { public void eat() { System.out.println("Eating"); } } public class Dog inherits Animal { public void bark() { System.out.println("Barking"); } } ```
While this syntax was valid in earlier versions of Java, it's now considered outdated and should be avoided.
Understanding these keywords is crucial for any Java developer. They form the backbone of Java's object-oriented programming model, enabling code reusability, polymorphism, and multiple inheritance through interfaces. As you continue your Java journey, remember to leverage these tools to create efficient, maintainable, and extensible code.