zoukankan      html  css  js  c++  java
  • get(0)??

    今天学习object类型的多态时遇到了get(0)这个东西,不懂是什么意思。

    附上代码:

    import java.util.*;
    
    public class Dog {
      String name;
    
      public void eat() {
        System.out.println("吃骨头");
      }
    
      public static void main(String[] args) {
        ArrayList<Dog> test = new ArrayList<Dog>();
        Dog a = new Dog();
        test.add(a);
        Dog d = test.get(0);//此处惊现疑云
      }
    }

    ///////////////////////////////另外

    ArrayList<Object> myDogArrayList = new ArrayList<Object>();//实例化“对象”
    //Dog aDog = new Dog();
    myDogArrayList.add(aDog);//添加对象(异类对象?)
    Object o = myDogArrayList.get(0); //将Object赋值给新的Object引用变量
    //up对象使用get函数 int i = o.hashCode(); o.bark();//不能这么做,因为Object根本就不知道什么是bark()
  • 相关阅读:
    Piggy-Bank (hdoj1114)
    Word Amalgamation(hdoj1113)
    Lowest Bit(hdoj1196)
    1206: B.求和
    1207: C.LU的困惑
    STL初步
    关于521(nyoj)
    first blood暴力搜索,剪枝是关键
    变态最大值(nyoj)
    烧饼(nyoj779)
  • 原文地址:https://www.cnblogs.com/popjohn/p/3314540.html
Copyright © 2011-2022 走看看