【发布时间】:2019-10-07 04:36:30
【问题描述】:
我正在用 Java 编写一个程序,我遇到了这个问题。
我创建了一个抽象超类Customer 和一个子类RegisteredCustomer,当然还有主类。我找不到在 main 中使用 RegisteredCustomer 的构造函数的方法。
消息The method RegisteredCustomer(String, long, String, String) is undefined for the type RegisteredCustomer 即使我在RegisteredCustomer 中使用这些参数创建了确切的构造函数。
我试过RegisteredCustomer.RegisteredCustomer(fn , tel , adr , em);
和Customer.RegisteredCustomer.RegisteredCustomer(fn , tel , adr , em);
注册客户
public class RegisteredCustomer extends Customer {
private static int count = 0;
private int id;
private String email;
private String password;
public RegisteredCustomer(String fullName, long telephone, String adress, String email) {
super(fullName, telephone, adress);
this.id = ++ count;
this.email = email;
Customer.getCustomers().add(Customer.getCustomers().size() , this);
}
主要
RegisteredCustomer.RegisteredCustomer(fn , tel , adr , em);
【问题讨论】:
-
我不确定您的代码是否正确,但应该是
RegisteredCustomer rc = new RegisteredCustomer(fn, tel, adr, em);顺便说一句,一般不要将电话号码存储得太长。 -
你建议我如何存储电话号码?
-
电话号码是一个字符串。你打算如何将“0118 960 194”存储为long?参见,例如,What's the right way to represent phone numbers?