You create an inheritance relationship with the extends keyword. The child class name comes first, then extends, then the parent class name.
public class Animal {
String name;
void eat() {
System.out.println(name + " is eating");
}
}
public class Dog extends Animal {
void bark() {
System.out.println(name + " says Woof!");
}
}
Now Dog has the name field and the eat() method from Animal, plus its own bark() method. You don't redeclare name or eat() in Dog. They're inherited automatically.
Java allows only single inheritance. A class can extend exactly parent. If you write class Dog extends Animal, Pet, the compiler rejects it.