🎓 Top 15 Udemy Courses (80-90% Discount): My Udemy Courses - Ramesh Fadatare — All my Udemy courses are real-time and project oriented courses.
▶️ Subscribe to My YouTube Channel (178K+ subscribers): Java Guides on YouTube
▶️ For AI, ChatGPT, Web, Tech, and Generative AI, subscribe to another channel: Ramesh Fadatare on YouTube
The extends keyword is used in a class or interface declaration to indicate that the class or interface being declared is a subclass of the class or interface whose name follows the extends keyword.
extends Java Keyword Examples
In below example, we have created Animals superclass and Dog and Cat subclasses extends an Animals superclass.
abstract class Animals {
/** All kind of animals eat food so make this common to all animals. */
public void eat() {
System.out.println(" Eating ..........");
}
/** The make different sounds. They will provide their own implementation */
abstract void sound();
}
class Cat extends Animals {
@Override
void sound() {
System.out.println("Meoww Meoww ........");
}
}
class Dog extends Animals {
@Override
void sound() {
System.out.println("Woof Woof ........");
}
}
Note that interface can extends other interfaces like:
public interface A{
}
public interface B extends A {
}
Comments
Post a Comment
Leave Comment