没有构造函数的Java类? [英] Java class with no constructor?

查看:139
本文介绍了没有构造函数的Java类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个类

class Customer{
    int ID;
    Time arriveTime;
    Time serviceTime;
    Time completeTime;
    int transaction;
}

我不需要一个构造函数来设置里面的值?我将使用这个类来保存不同的值,同时创建一个Customers的数组。

Don't I need a constructor in order to set the values inside? I will be using this class to hold different values while making an array of Customers. Wouldn't this mean I would need this in order to set the values?

public Customer(int id, Time arrive, Time service, Time complete, int trans){
            ID = id;
            arriveTime = arrive;
            serviceTime = service;
            completeTime = complete;
            transaction = trans;
}



我只需要Customer类保存每个客户的信息。 p>

I only need the Customer class to hold the information about each customer.

推荐答案

不一定,默认情况下,没有可见性修饰符的属性(值)

Not necessarily, as by default your attributes (values) without a visibility modifier can be set directly on instances of Customer from code in the same package.

例如:

Customer c = new Customer(); // default constructor 
c.ID = 5;
... (etc.)

更多修饰符的访问级别

这篇关于没有构造函数的Java类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆