Java构造函数未定义?

Jer*_*rry 5 java methods constructor

好的,我正在为学校做作业,我设置了我的主类,还有另一个名为Transaction的类.在我的主要课程中,我有:

Transaction t = new Transaction();
Run Code Online (Sandbox Code Playgroud)

并强调了Transaction:它表示构造函数未定义.为什么?!

Transaction类看起来像这样:

public class Transaction {

private String customerNumber, fName, lName, custAddress, custCity;
private int custZip, custPhone;

/** Constructor*/
public Transaction(String a, String b, String c, String d, String e, int f, int g){
    this.customerNumber = a;
this.fName = b;
this.lName =c;
this.custAddress = d;
this.custCity = e;

}
Run Code Online (Sandbox Code Playgroud)

它看起来应该只是起作用,但事实并非如此.即使我将一堆变量插入到我在main中创建新Transaction对象的位置,它仍然表示未定义.有人请帮忙!

Pra*_*rav 9

您的类中没有默认的构造函数定义.

当您提供至少一个参数化构造函数的定义时,编译器不再为您提供默认构造函数.


Tom*_*Tom 5

这是因为您没有声明没有参数的构造函数.

如果根本没有定义构造函数,则会有一个默认构造函数,不会自动为您定义任何参数.

但是现在你已经声明了一个带参数的构造函数,你现在需要传递它们或声明另一个没有参数的构造函数.