java binarynode_Java Class isntance(使用ToString方法覆盖)输出“adt.BinaryNode@1e24e45”

你好我已经在我自己的类中覆盖了toString()方法,但不知何故输出并不是我想要的.对不起新手问题,但我不知道问题出在哪里,任何提示/帮助主要是赞赏.谢谢.

我的课:

public class Country implements Comparable{

private String name;

private String capital;

private int area;

public Country(String a, String b, int c) {

this.name = a;

this.capital = b;

this.area =c;

}

@Override

public String toString(){

return(this.name + " "+ this.capital+" " + this.area);

}

}

DS:

private void preorder(BinaryNode a){

if (a != null){

System.out.println(a.toString());

preorder(a.left);

preorder(a.right );

}

}

应用程序:

BinarySearchTree db = new BinarySearchTree();

Country ob = new Country("Romania", "Buc", 123);

db.addNewElement(ob);

ob = new Country("Hungaria", "Bud", 50);

db.addNewElement(ob);

ob = new Country("Vatican", "Vat", 1);

db.addNewElement(ob);

db.printAll();

输出:

adt.BinaryNode@1e5e2c3

adt.BinaryNode@18a992f

adt.BinaryNode@4f1d0d

编辑:修复“chaitanya10”暗示msitake

DS:

private void preorder(BinaryNode a){

if (a != null){

System.out.println(a.elm.toString()); // ACCES the data in node not the hole node.

preorder(a.left);

preorder(a.right );

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值