【问题标题】:Naming objects incrementally以递增方式命名对象
【发布时间】:2012-03-19 22:34:06
【问题描述】:

我想知道每次运行方法时如何为新对象命名不同的名称

public class Horse extends Animal{
int horsenum = 0;

}
public  void reproduce(Horse h){
    horsenum ++;
    Horse newHorse = new Horse(); //Here is where I would like to name the new horse "newHorse1, newHorse2, etc."

【问题讨论】:

  • horsenum设为静态,它应该可以工作..
  • @MikeChristensen:你确定这会稳定吗?稳定的!格迪特?
  • @skaffman - 除非马在赛道上..那么你可能有比赛条件..

标签: object naming


【解决方案1】:

添加 Horse.Name ofType 字符串的属性并将其命名为您想要的...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-05-25
    • 2013-07-20
    • 2015-07-13
    • 1970-01-01
    • 2017-08-01
    • 1970-01-01
    • 2012-01-23
    • 1970-01-01
    相关资源
    最近更新 更多