【Java每日一题】20161108

来源:互联网 时间:2016-11-08

package Nov2016;

import java.util.TreeSet;

public class Ques1108 {

public static void main(String[] args){

Animal dog = new Animal("dog");

Animal cat = new Animal("cat");

TreeSet<Animal> animals = new TreeSet<Animal>();

animals.add(dog);

animals.add(cat);

System.out.println(animals); // 1

}

}

// 动物类

class Animal implements Comparable<Animal>{

private String name;

Animal(String name){

this.name = name;

}

@Override

public int compareTo(Animal o){

return 0;

}

@Override

public String toString(){

return name;

}

}

今日问题: 
请问注释1处输出结果是什么?(点击以下“【Java每日一题】20161108”查看20161107问题解析) 


题目原发布于公众号、简书:【Java每日一题】20161108,【Java每日一题】20161108 
每日一题最新将在公众号发布,欢迎订阅,交流进步 

 

相关阅读:
Top