我遇到的问题是,虽然我相信我已经在构造函数中正确设置了所有内容,但是当我尝试调用from
新Letter
实例的实例变量时,我fromto
似乎不断收到错误消息,提示编译器找不到变量fromto
。目标是Dylan
与文本一起出现。
public class Letter {
private String from; // Sets from instance variable to be stored
private String to; /// Sets to instance vaariable to be stored
public Letter(String from, String to) {
this.from = from;
this.to = to;
}
public Letter() {
Letter fromto = new Letter("Dylan", "April");
}
public static void main(String[] args) {
System.out.println("Dear " + fromto.from);
}
}