
new创建对象时需要使用运算符
Contacts.add(new Data(name, address, contact)); // Creating a new object and adding it to list - single step
要不然
Data objt = new Data(name, address, contact); // Creating a new objectContacts.add(objt); // Adding it to the list
并且您的构造函数不应包含
void。否则它将成为您班上的一个方法。
public Data(String n, String a, String c) { // Constructor has the same name as the class and no return type as such欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)