博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
extends_Keyword
阅读量:3925 次
发布时间:2019-05-23

本文共 991 字,大约阅读时间需要 3 分钟。

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 {}

转载地址:http://xbgrn.baihongyu.com/

你可能感兴趣的文章
Leetcode 304. 二维区域和检索 - 矩阵不可变
查看>>
Leetcode 45. 跳跃游戏 II
查看>>
模式2. 工厂方法模式-Java
查看>>
模式1. 简单工厂模式-Java
查看>>
模式6.原型模式-Java
查看>>
Leetcode 146. LRU 缓存机制
查看>>
Leetcode 208. 实现 Trie (前缀树)
查看>>
Leetcode 1114. 按序打印
查看>>
kill -15、kill -9 与 kill
查看>>
剑指 Offer 05. 替换空格
查看>>
剑指 Offer 06. 从尾到头打印链表
查看>>
模式9.建造者模式-Java
查看>>
模式11. 抽象工厂模式-Java
查看>>
模式10. 观察者模式-Java
查看>>
剑指 Offer 09. 用两个栈实现队列
查看>>
模式12.状态模式-Java
查看>>
Volatile-1.保证可见性
查看>>
Volatile-2.不保证原子性
查看>>
剑指 Offer 25. 合并两个排序的链表
查看>>
剑指 Offer 26. 树的子结构
查看>>