小编use*_*518的帖子

构造函数和字符串第2部分示例

我遇到的问题是,虽然我相信我已经在构造函数中正确设置了所有内容,当我尝试调用from我的新Letter实例的实例变量时,我fromto似乎不断收到错误,说编译器无法找到变量fromto.目标是Dylan使用Text显示.

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);

    }

}
Run Code Online (Sandbox Code Playgroud)

java

2
推荐指数
1
解决办法
52
查看次数

标签 统计

java ×1