extends_Keyword 妖狐艹你老母 2021-11-05 08:30 236阅读 0赞 extends Java Keyword with Examples 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 { }
还没有评论,来说两句吧...