-
代码:
class NPC1 { private String Name = "NPC1"; public String GetName(){return Name;} public void Talk(String Name) { System.out.println("Hello " + Name); } } class NPC2 { private String Name = "NPC2"; public String GetName(){return Name;} public void Talk(String Name) { System.out.println("Hello " + Name); } } class TalkManager { public static void main(String[] args) { NPC1 npc1=new NPC1(); NPC2 npc2=new NPC2(); npc1.Talk(npc2.GetName()); npc2.Talk(npc1.GetName()); } }
Java学习-如何实现两个对象之间互发消息?
最新推荐文章于 2022-06-22 14:45:33 发布