Question: Implementation of Data Hiding Whats is Data Hiding? Within the DeclareTwoEmployees class, you must use the public methods setEmpNum() and getEmpNum()to be able to set

Implementation of Data Hiding
Whats is Data Hiding?
Within the DeclareTwoEmployees class, you must use the public methods  setEmpNum() and getEmpNum()to be able to set and retrieve the value of the empNum field  for each Employee because you cannot access the private empNum field directly. For example,  the following statement would not be allowed:
clerk.empNum = 789;

This statement generates the error message "empNum has private access in  Employee", meaning you cannot access empNum from the DeclareTwoEmployees class. If  you made empNum public instead of private, a direct assignment statement would work, but  you would violate an important principle of object-oriented programming—that of data hiding  using encapsulation. Data fields should usually be private, and a client application should be  able to access them only through the public interfaces—that is, through the class's public  methods.
 

To do:
A. Make a class consisting of data fields. Include a method that displays the values in addition to instance methods that set the values of the data fields.
B. Make at least three objects should be instantiated by the Main Class.

PS: You are free to be as creative as you like as long as you adhere to the rules.

 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!