answersLogoWhite

0


Best Answer

The "private" attribute causes the method, object, or class to which it is applied to become inaccessible to code outside of its "private" scope. This means that a compiler will issue an error if any code outside of the "private" scope attempts to access the method, object, or class that is marked as private. You should use this when you wish to ensure that your data's integrity is maintained when other code could use it.

Some common industry examples: singleton objects (only one may exist at any time), a class that manages its internal state would use only accessor and mutator functions to allow outside code access (known as encapsulation, a foundation of object-oriented programming; often called a class' API), and business logic protection (by restricting certain functions to only a formal instance of a class, and not its subclasses).

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Why should you use private attribute and example?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

How can you disable a particular part in the source code of CSS?

Put /* block comments */ around it, for example: style { attribute: value; attribute: value; attribute: value; } style { /* attribute: value; */ attribute: value; attribute: value; } or style { /* attribute: value; attribute: value; */ attribute: value; } or /* style { attribute: value; attribute: value; attribute: value; } */ And while this won't validate, attribute renaming uses a lot less typing (and I use it myself): style { xattribute: value; attribute: value; attribute: value; }


What is the use of name attribute in designing form in HTML and what happens if not used?

The name attribute can be used for referring the value in other context. For example for passing the value in JavaScript.


How can you align images to the right of a table using css tag?

In your CSS document, use the float attribute with your img tag. For example: img.example { float:right; }


When is it good idea to calculate an object's attribute on the fly rather than storing it as a data member?

The only time you should calculate it instead of storing is when you only use that attribute once. Otherwise, store it to avoid repeating calculations.


How do you use the async attribute in html5?

The async and defer attributes are boolean attributes that indicate how the script should be executed. The defer and async attributes must not be specified if the src attribute is not present. There are three possible modes that can be selected using these attributes. If the async attribute is present, then the script will be executed asynchronously, as soon as it is available. If the async attribute is not present but the defer attribute is present, then the script is executed when the page has finished parsing. If neither attribute is present, then the script is fetched and executed immediately, before the user agent continues parsing the page.

Related questions

How can you disable a particular part in the source code of CSS?

Put /* block comments */ around it, for example: style { attribute: value; attribute: value; attribute: value; } style { /* attribute: value; */ attribute: value; attribute: value; } or style { /* attribute: value; attribute: value; */ attribute: value; } or /* style { attribute: value; attribute: value; attribute: value; } */ And while this won't validate, attribute renaming uses a lot less typing (and I use it myself): style { xattribute: value; attribute: value; attribute: value; }


What is the use of name attribute in designing form in HTML and what happens if not used?

The name attribute can be used for referring the value in other context. For example for passing the value in JavaScript.


Which 2 file attributes should not be used together?

You can use any attribute togather.. No harm in it..


How do you use border in HTML?

Border can be an attribute in html. For example, in the table tag. This will put a border around the table.As another example, it can be used in the img tag.


What are key attribute and non key attribute?

Attributes can be classified as identifiers or descriptors. Identifiers, more commonly called keys or key attributes uniquely identify an instance of an entity. If such an attribute doesn't exist naturally, a new attribute is defined for that purpose, for example an ID number or code. A descriptor describes a non-unique characteristic of an entity instance. An entity usually has an attribute whose values are distinct for each individual entity. This attribute uniquely identifies the individual entity. Such an attribute is called a key attribute. For example, in the Employee entity type, EmpNo is the key attribute since no two employees can have same employee number. Similarly, for Product entity type, ProdId is the key attribute. There may be a case when one single attribute is not sufficient to identify entities. Then a combination of attributes can solve this purpose. We can form a group of more than one attribute and use this combination as a key attribute. That is known as a composite key attribute. When identifying attributes of entities, identifying key attribute is very important.


How do you use a sentence with the word attribute?

I would attribute my good looks to my handsome father.


Use attribute in a sentence?

The attribute that most impressed the hiring manager was the candidate's strong communication skills.


When you assign each anchor to its own anchor name you use what attribute?

Name attribute


What attributes in HTML let you specify the thickness and width of a horizontal rule?

In HTML 4.01, the "size" attribute specifies thickness and the "width" attribute specifies width, as measured in pixels. For example: <hr size="20" width="800" /> However, these attributes are deprecated in XHTML Strict and HTML 5--you should use CSS instead.


What is the right use of the lang attribute?

no


Should small businesses use private loans?

Small businesses should use private loans if necessary for the business to succeed, I would contact your bank for options in private loans, as well as other loan options.


Should the WAN use a private or public infrastructure?

privet