zoukankan      html  css  js  c++  java
  • java 多态,接口,抽象类的认识

    1, 

     多态 : 父类的引用指向子类对象,有继承,有重写 

     多态表达了  :  cat 是一种 Animal  

     规则 : 多态对象不能调用父类中没有的方法

     定义 :   Animal cat = new Cat();

    2, 

     接口 :  类实现接口implement,也是一种极度抽象的抽象类,也是类很多行为的集合

     接口表达了 : cat 具有 jump 的行为能力

     规则 : 成员非静态方法自动为public , 不可以有方法体, 可以有返回值,可以有参数

        成员属性自动为public final static

        必须实现接口中的方法

    定义 : 1)  接口 public interface DoolFun{      

              public static float pi = 3.45f;
              void alert();

           }

         2) 实现接口  public class dool implements DoolFun{        

              @Override
              void open() {
              // TODO Auto-generated method stub
                  System.out.println("open box");
              }

           }

    3, 

     抽象类 :  类可以继承抽象类extends , 是类统一具有的行为的集合,抽象类只是一种稍微特殊的类而已

     抽象类表达了 :cat 具有 eat 的行为  

     规则 :  成员方法可以有方法体,可以包含非抽象方法,但抽象的方法和接口中的方法一样,必须在子类中实现,没有方法体

                抽象类可以实现多态

            抽象的成员自动为 public 

     定义 :  1) 抽象类 abstract class Animals{}

        2) 继承  public class Dog extends Animals

  • 相关阅读:
    Android6.0以后动态增加权限
    Failed to resolve: junit:junit:4.12
    tflite
    error: undefined reference to `cv::imread(std::string const&, int)'
    Makefile
    tf模型可视化工具
    linux c++下遍历文件
    mobilenetV3
    centos7安装mxnet
    chrome的一些插件
  • 原文地址:https://www.cnblogs.com/yubolin/p/5197565.html
Copyright © 2011-2022 走看看