登录
  • #公开课
  • #入门|算法|数据结构

CS‌‌‍‍‌‍‍‌‌‍‌‌‌‌‍‍‌‌‍‍‍‌‌‍‍‌‍‍‌‌‍‍ 61B 一道Discussion求助

一亩三分地匿名0D7
506
1
public class Horse {

Horse same;

String jimmy;

public Horse(String lee) {

jimmy = lee;

}

public Horse same(Horse horse) {

if (same != null) {

Horse same = horse;

same.same = horse;

same = horse.same;

}

return same.same;

}

public static void main(String[] args) {[br]
Horse horse = new Horse("youve been");

Horse cult = new Horse("horsed");

cult.same = cult;

cult = cult.same(horse);

System.out.println(cult.jimmy);

System.out.println(horse.jimmy);

}

}

请问为什么程序执行到cult = cult.same(horse);时候

return same.same 的return的reference type会是cult,不应该是horse吗?

谢谢大家帮助!
1条回复
热度排序

发表回复