Let’s say we’re designing an Employee class that has two data fields. One data field, called id, is for storing each employee’s ID number. Another data field, called numEmployees, keeps track of how many Employee objects have been created. For each of the blanks, indicate the appropriate choice.
id should be ( public/private ) and (
static/not static )
numEmployees should be (public/private) and
(static/not static )
Solution:-
Id should be public and non static
Explanation:- Beacuse id attribute is unique for every object i.e id as instance variable. Id must be declared public so that it can be accessed and modified outside the class. And it must be non static Beacuse it is unique for every object.
numEmployees should be private and static
Because numEmployees is class level variable i.e it is same for every employee. Thus it must be declared as static and also it can not be modified outside class hence it must be declared as private.
Get Answers For Free
Most questions answered within 1 hours.