zoukankan      html  css  js  c++  java
  • [Java] 对象转型-02

    package com.bjsxt.chap03;
    
    public class Cast_02 {
    
        public static void main(String[] args) {
            Cast_02 test = new Cast_02();
            Animal a = new Animal("AnimalName");
            Cat c = new Cat("catName", "blue");
            Dog d = new Dog("dogName", "block");
            test.f(a);
            test.f(c);
            test.f(d);
        }
        public void f(Animal a) {
            System.out.println("name : " + a.name);
            if (a instanceof Cat) {
                Cat cat = (Cat)a;
                System.out.println(" " + cat.eyescolor + " eyes");
            } else if (a instanceof Dog) {
                Dog dog = (Dog)a;
                System.out.println(" " + dog.furcolor + " fur");
            }
        }
    }

  • 相关阅读:
    HttpClient
    充值保存
    button 样式
    创建窗口
    第十一次作业
    第十次作业
    第九次作业
    第八次作业
    第七次作业
    第六次作业
  • 原文地址:https://www.cnblogs.com/robbychan/p/3786589.html
Copyright © 2011-2022 走看看