Java class with no constructor?

前端 未结 5 1274
心在旅途
心在旅途 2021-01-27 16:46

I have this class

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

Don\'t I

5条回答
  •  孤街浪徒
    2021-01-27 17:45

    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.

    For example:

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

    More on modifier access levels here.

提交回复
热议问题