105k views
5 votes
Consider a class called Rocket that has a private instance variable called Engine. You are writing a "getter" for the Engine. Using the guiding principles of data encapsulation, under what circumstances is it allowed to return a reference to the existing Engine?

1 Answer

5 votes

Answer:

when user wants duplicate copy of the object

Step-by-step explanation:

Encapsulation are one of the key foundations of object-oriented programming (OOP). It involves the bundling of data or information with the methods and various techniques which operate on that data.

It can be used in hiding the true values or state of a structured data object that is in a class, preventing unauthorized parties' direct access to them.

The circumstances that can be allowed in returning a reference to the existing Engine is when user wants duplicate copy of the object.

User Russell Leggett
by
4.4k points