我试图通过main函数调用我的对象。由于它需要静态引用,但我却无法做到。有人可以告诉我我在做什么错吗?
private double checking;
private double saving;
public BankDisplay(double checking,double saving) // Constructor for subclass
{
checking=1000;
saving=1000;
}
public void setChecking(double checking){
this.checking=checking;
}
public double getChecking(){
return checking;
}
public void setSaving(double saving){
this.saving= saving;
}
public double getSaving(){
return saving;
}
BankDisplay checking1=new BankDisplay(checking, saving);
BankDisplay savings1= new BankDisplay(checking,saving);
当我尝试打印对象checking1和save1主要时,它显示“无法为静态函数提供非静态引用”。
最佳答案
public BankDisplay(double checking,double saving) // Constructor for subclass
{
this.checking=checking;
this.saving=saving;
}
There is an error in constructor.
public static void main(String[] args){
BankingDisplay d1 = new BankingDisplay(100.15,200.15);
System.out.println(d1.getChecking());
}