answersLogoWhite

0


Best Answer

As my AP Computer Science teacher eloquently said:

"You can't let strangers touch your private parts"

Therefore, if data was not hidden, a client class can modify all the variables(given that it is not a final constant) by simply calling:

className.variableName = newWrongData;

By using special methods to access the variables, the class can change its internal implementation, without breaking compatibility with other classes that are already using it.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago


In Java, you hide data by declaring it private. In that case, it is not visible outside the class. When you do that, you should provide set and get methods (they can have any name, but starting them with "set" and "get" is a common coding standard). Example:

class Person
{
private String name;

void setName(parameterName) {name = parameterName;}

String getName() {return name;}

}

By hiding the data, you may later decide to change the implementation, without breaking compatibility with existing code that uses your class. It is general recommended to hide all class fields.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Why should an object hide its data?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is Data Hiding in VBNET?

Data hiding is used method used in Object-Oriented programing to hide information within computer code


What are some things you should do if you hear that there is a cyclone warning in your area?

you should go in your basement and hide under a heavy object.


Data maintained about the data within the data warehouse is defined as?

Data about other data is metadata.


Why encapsulation does not implement information hiding in object orientation?

Encapsulation also implements data hiding in an object oriented programming design. By encapsulating various methods & data objects into a single class they can also be hidden from all the other classes. You can declare the variables and methods as private and that way you can hide the data from the other classes in the application.


Use to compare data side by side which of the following object should you select?

TableChartOutlineGrid


What is adodc?

Acitex data object database


Is a technique that can be used to conceal data that might not be relevant to a particular report or sensitive data that others should not see?

You can hide a column or row, so they do not appear or you can format the cell contents to be white instead of black (format cell contents to the same color as the cell background).


Best way to generate test data for a 3D object recognition engine Data should have the form 'xyz rgb objtype' where xyz is a point on the object's surface rgb is the point's color?

16,421 - 14,831


RdoQuery in The rdoConnection object is not connected to a data source?

The rdoConnection object is not connected to a data source?


When was Object Data Management Group created?

Object Data Management Group was created in 1991.


What database object stores the data?

Tables are the database objects that store data in a structured format within a relational database management system (RDBMS). Tables consist of rows and columns where the actual data is stored. Each row represents a record, and each column represents a field or attribute.


Advantages and disadvantages of manual data processing?

disadvantages in data manual processing