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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started