【问题标题】:initialize the instance variable with a constructor使用构造函数初始化实例变量
【发布时间】:2013-10-06 10:45:06
【问题描述】:

就我现在而言,我有这个:

类车辆{

int 注册号;

现在我需要为 registrationNumber 创建一个构造函数。 我该怎么做呢? (我已经看到了一些这个。= 这是什么。怎么办?

【问题讨论】:

  • 你要我们做你的功课吗?这是什么语言,你试过什么?

标签: variables constructor initialization instance


【解决方案1】:

this 关键字返回对当前对象的引用。

class Vehicle{

    int registrationNumber;

    Vehicle(int registrationNumber){
        this.registrationNumber = registrationNumber;
    }

}

【讨论】:

    猜你喜欢
    • 2015-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-27
    • 2015-02-19
    相关资源
    最近更新 更多