Entri Blog
No Result
View All Result
Thursday, June 8, 2023
  • State PSC
    • Kerala PSC
    • TNPSC
    • APPSC
    • TSPSC
    • BPSC
    • Karnataka PSC
    • MPPSC
    • UPPSC
  • Banking
    • IBPS PO Notification
    • IBPS Clerk Notification
    • SBI PO Notification
    • SBI Clerk Notification
    • SBI SO Notification
    • SBI Apprentice Notification
    • Canara Bank PO Notification
    • Indian Bank PO Notification
    • RBI Assistant Notification
    • RBI Office Attendant Notification
    • IBPS RRB Notification
    • IBPS RRB Office Assistant Notification
  • Govt Exams
    • Railway
    • SSC
  • Skilling
    • Coding
    • Spoken English
    • Stock Marketing
  • TET
    • APTET
    • CTET
    • DSSSB
    • Karnataka TET
    • Kerala TET
    • KVS
    • MPTET
    • SUPER TET
    • TNTET
    • TSTET
    • UPTET
  • Courses
    • Data Science Course
      • Data Science Malayalam
    • Full Stack Developer Course
      • Full Stack Development Malayalam
      • Full Stack Development Hindi
      • Full Stack Development Tamil
      • Full Stack Development Telugu
      • Full Stack Development Kannada
    • Stock Market Course
      • Stock Market Course in Malayalam
      • Stock Market Course in Tamil
      • Options Trading Course
    • Spoken English Course
      • Spoken English Course in Malayalam
      • Spoken English Course in Hindi
      • Spoken English Course in Telugu
      • Spoken English Course in Tamil
      • Spoken English Course in Kannada
    • Python Programming Course
    • Practical Accounting Course
    • Quantity Surveying Course
  • Others
    • GATE
    • MAT
    • KMAT
    • UPSC
Try out Spoken English!
Entri Blog
  • State PSC
    • Kerala PSC
    • TNPSC
    • APPSC
    • TSPSC
    • BPSC
    • Karnataka PSC
    • MPPSC
    • UPPSC
  • Banking
    • IBPS PO Notification
    • IBPS Clerk Notification
    • SBI PO Notification
    • SBI Clerk Notification
    • SBI SO Notification
    • SBI Apprentice Notification
    • Canara Bank PO Notification
    • Indian Bank PO Notification
    • RBI Assistant Notification
    • RBI Office Attendant Notification
    • IBPS RRB Notification
    • IBPS RRB Office Assistant Notification
  • Govt Exams
    • Railway
    • SSC
  • Skilling
    • Coding
    • Spoken English
    • Stock Marketing
  • TET
    • APTET
    • CTET
    • DSSSB
    • Karnataka TET
    • Kerala TET
    • KVS
    • MPTET
    • SUPER TET
    • TNTET
    • TSTET
    • UPTET
  • Courses
    • Data Science Course
      • Data Science Malayalam
    • Full Stack Developer Course
      • Full Stack Development Malayalam
      • Full Stack Development Hindi
      • Full Stack Development Tamil
      • Full Stack Development Telugu
      • Full Stack Development Kannada
    • Stock Market Course
      • Stock Market Course in Malayalam
      • Stock Market Course in Tamil
      • Options Trading Course
    • Spoken English Course
      • Spoken English Course in Malayalam
      • Spoken English Course in Hindi
      • Spoken English Course in Telugu
      • Spoken English Course in Tamil
      • Spoken English Course in Kannada
    • Python Programming Course
    • Practical Accounting Course
    • Quantity Surveying Course
  • Others
    • GATE
    • MAT
    • KMAT
    • UPSC
No Result
View All Result
Entri Blog
Spoken English
banner top article banner top article
Home Articles

Data Hiding in C++ – Introduction, Example

by Kiranlal VT
May 11, 2023
in Articles, Entri Elevate, Entri Skilling
Data Hiding in C++ - Introduction, Example
Share on FacebookShare on WhatsAppShare on Telegram

Data hiding is a method for concealing data members, which are internal features of an object. It is an approach to object-oriented programming. Data concealing assures, or maybe we should say guarantees, that only members of the class have access to the data. It preserves the data’s integrity. To restrict direct access from outside the class, data hiding refers to concealing internal data within the class. By reducing the interdependencies between software components, data hiding also contributes to a reduction in system complexity and an improvement in resilience. By employing the private access specifier, data may be hidden. Data hiding, or simply concealing data members, is a programming method used in object-oriented environments. Data hiding maintains object integrity and ensures that class members have limited access to data.

Learn Full Stack Development with experts! Explore Here!

A class’s members are better protected when data is hidden. There are access modifiers like public, private, and protected in programming languages like Java. Other classes’ objects have access to public data members and methods. However, objects belonging to the same class and its subclasses can access protected members. Additionally, only members of the class have access to private members. As a result, these access modifiers aid in keeping the members safe. The private access modifier can be used by a programmer to prevent objects of other classes from accessing a class’s members when it is essential. Then, only members of the class may access the data. Additionally, it is possible to make the data members public while keeping them private (getters and setters).

Introduction to Data Hiding in C++

Since data is the most delicate and unstable part of a program, tampering with it can lead to erroneous results and jeopardize data integrity. Data hiding is useful in this situation. Data concealing aims to shield information inside a class from unauthorized access and prevents unnecessary intrusion from outside the class. In C++, data hiding ensures restricted data access, protects the integrity of the object, and hinders accidental or deliberate modifications to the program. In C++, the technique of concealing computer code from object members is known as data hiding. If an object member tries to access hidden data, the program will produce an error. The programmer cannot connect to data that has been buried since it is inaccurate due to this safety feature. Internal parts that aren’t expected to be used by users are usually hidden. In C++, abstraction and encapsulation are two more OOP characteristics that go hand in hand with data hiding.

Example of Data Hiding in C++

To conceal internal object information, object-oriented programming (OOP) uses the software development method known as data hiding (data members). Data hiding guarantees that class members have exclusive access to data and safeguards object integrity by avoiding accidental or deliberate alterations. Let us look at an example of data hiding in C++ by finding out the area of a rectangle:

#include<iostream>

using namespace std;

class Rectangle

{

public :

int length;

int breadth;

int area()

{

return length*breadth;

}

int perimeter()

{

return 2*(length+breadth);

}

};

int main()

{

Rectangle r,*p;//Using Stack

p=&r;

p->length=5;

p->breadth=10;

cout<<“Stack Area : “<<p->area()<<endl;

 

Rectangle *h=new Rectangle(); //Using Heap

h->length=10;

h->breadth=10;

cout<<“Heap Area : “<<h->area();

return 0;

}

Output: Stack Area: 50

Heap Area: 100

Data Abstraction

Data abstraction is a method for simply displaying to the user the essential program interface and concealing the more intricate implementation details. Let’s examine a real-world case to have a better understanding. Check out what’s on your television. The television can be turned on and off, the channel can be changed, the volume can be changed, and speakers and external devices like VCRs and DVD players can be connected. You aren’t aware of the television’s interior workings, though. Data abstraction shields class implementation from unexpected mistakes and enables it to adapt to evolving needs or problem reports without needing user involvement.

Elevate your career with Entri Elevate! Explore Here!

Data abstraction is a typical technique used by modern programming languages that employ OOP approaches to hide the low-level details of the programming constructs that define the underlying logic, which in turn simplifies and speeds up the development process. Instead of focusing on functions or logic, object-oriented programming centers software architecture on data objects. A crucial aspect of OOP is data abstraction, which is carried out through classes and objects. The definition of a class is a template that groups associated properties and methods into a named package. It is a unique kind of thing that acts as a design template for making additional objects. A class can also have subclasses, which can inherit all or some of the class’s characteristics and functions, creating a kind of class hierarchy. Subclasses are also allowed to create their properties and functions.

Data Encapsulation

The act of combining data with related functions into a single entity known as a class is known as data encapsulation. Simply said, if you have a property that is invisible from the outside of an object and bundles it with methods that provide read or write access to it, you may hide sensitive information and restrict access to the internal state of a thing. As a consequence, depending on the techniques you select, it’s up to you to decide whether an attribute may be read and modified, read-only, or not visible at all. Data abstraction is a method of exposing only the interfaces and shielding the user from the implementation details. Data encapsulation is a method of combining the data and the functions that utilize it.

Difference Between Data Hiding and Data Encapsulation

Encapsulation and Data Hiding are two OOP concepts. Data hiding is the process of preventing unauthorized access to the class’s members. The act of encapsulating data elements and method calls into a single entity is called encapsulation. That is the distinction between data encapsulation and data concealing. A method of achieving data concealing is encapsulation.

  • By limiting unintentional or intentional modifications, data hiding assures exclusive data access to class members and maintains object integrity. A technique used in OOP called encapsulation groups together the data and the methods that work with it.
  • The goal of data concealing is to protect the data while obscuring its complexity. The goal of encapsulation is to mask the system’s complexity.
  • Data protection is achieved by data concealing. A technique for accomplishing data concealing is encapsulation.
  • Using the private access modifier, data is hidden. Private, protected, and public access modifiers are used in encapsulation.

Access Specifiers

By allowing the construction of user-defined types, or classes, C++ provides data hiding and, by extension, data abstraction and data encapsulation. Access specifiers are a class of keywords that specify the range of this newly generated class’s members. Private, protected, and public access specifiers are the three main forms of protection or access specifiers that are typically accessible inside a category and are used to develop a class’s encapsulation capabilities. Variables and functions of a type can be accessed in different ways depending on the access specifiers that are used. In most cases, a class’s actions are public while its data is private to prevent instances of unintentional tampering. However, there are no limitations on accessibility within a rank.

Application of Data Hiding

  1. Data that is erratic and sensitive are frequently subject to data concealment. The efficient and speedy operation of software depends on this kind of data. Due to unauthorized access, the ensuing data changes are irreversible and necessitate a complete rewrite on the part of the programmer before future usage.
  2. Data concealment shields students against unintended oversights. Typically, a class consists of several linked fields that must all be in a trustworthy condition. Let’s say a programmer is given direct access to any of these fields. In such circumstances, there’s a chance that you may make changes to one area without making changes to crucial linked areas, which would put your class in a conflicting situation.

Wrapping Up

The advantages of data hiding in C++ are numerous. It helps reduce the complexity and unpredictable nature of data. It makes the software more reusable. Decreasing interdependencies between software components also contribute to a reduction in system complexity and an improvement in resilience.

Data Hiding in C++ – Introduction, Example: FAQs
  • What does object-oriented programming’s term “encapsulation” mean?

Data and the programming that manipulates it can be connected through encapsulation. It is a method for making the data abstraction visible to the outside world while concealing the data implementation specifics.

  • What does object-oriented programming’s abstraction mean?

In object-oriented programming, abstraction is a method for separating class interfaces from the implementation specifics of each particular object.

  • How do classes and objects in object-oriented programming interact with one another?

The cornerstones of object-oriented (OO) programming are classes and objects. A programming paradigm known as object-oriented programming employs objects and classes to simulate the actual world.

Related Articles

Data Science Jobs in Kerala Importance of Data Preprocessing in Machine Learning
What is a Data Science Pipeline? Top Data Types of Python
What is Data Interpretation? Methods and Benefits Data Analysis – Process, Methods, Types
What is Data Science Life Cycle? Best Full Stack Developer Course with Placement
Future of Python Developers Use of Data Science in Banking for Fraud Detection
×








    Share63SendShare
    Kiranlal VT

    Kiranlal VT

    Related Posts

    Canara Bank GCCO Recruitment 2023
    Articles

    Canara Bank GCCO Recruitment 2023 Notification Out: Check The Last Date to Apply

    May 16, 2023
    Kerala PSC KSEB Sub Engineer Civil Recruitment Notification 2023 Out: PDF, Link
    Articles

    Kerala PSC KSEB Sub Engineer Civil Recruitment Notification 2023 Out: PDF, Link

    May 16, 2023
    Kerala PSC KSEB Sub Engineer Exam Syllabus
    Articles

    KSEB Sub Engineer Civil Syllabus and Exam Pattern 2023: PDF, Link

    May 16, 2023
    Next Post
    Principal Component Analysis in Machine Learning

    Principal Component Analysis in Machine Learning

    Discussion about this post

    More to Explore

    1. What is Data Interpretation? Methods and Benefits
    2. How Apple Uses AI, Data Science, And ML
    3. How Netflix Uses AI, Data Science, And ML
    4. How Netflix Uses AI, Data Science, And ML
    5. What is the Scope for Data Science in Kerala
    6. What is Data Modeling? Basic Concepts and Types
    7. How to Build a Career in Data Science and Analytics?
    8. Naive Bayes Classifier in Machine Learning
    9. 100 Machine Learning Interview Questions and Answers

    More to Learn

    1. Top 200 Data Engineer Interview Questions & Answers
    2. Top 12 Data Science Final Year Project Ideas
    3. Salary of Data Scientist – State Wise in India
    4. Top 100 Data Science Interview Questions and Answers
    5. Exploratory Data Analysis Techniques: Know the Difference
    6. Data Science Vs Data Analytics
    7. Artificial Intelligence and Machine Learning
    8. What is Logistic Regression in Machine Learning?
    9. Understanding Machine Learning Basics

    Courses

    • Data Science Course
    • Full Stack Developer Course
    • Data Science Course in Malayalam
    • Full Stack Developer Course in Malayalam
    • Full Stack Developer Course in Hindi
    • Full Stack Developer Course in Tamil
    • Full Stack Developer Course in Telugu
    • Full Stack Developer Course in Kannada

    Company

    • Become a teacher
    • Login to Entri Web

    Quick Links

    • Articles
    • Videos
    • Entri Daily Quiz Practice
    • Current Affairs & GK
    • News Capsule – eBook
    • Preparation Tips
    • Kerala PSC Gold
    • Entri Skilling

    Popular Exam

    • IBPS Exam
    • SBI Exam
    • Railway RRB Exam
    • Kerala PSC
    • Tamil Nadu PSC
    • Telangana PSC
    • Andhra Pradesh PSC
    • MPPSC
    • UPPSC
    • Karnataka PSC
    • Staff Selection Commission Exam

    © 2021 Entri.app - Privacy Policy | Terms of Service

    No Result
    View All Result
    • State PSC
      • Kerala PSC
      • TNPSC
      • APPSC
      • TSPSC
      • BPSC
      • Karnataka PSC
      • MPPSC
      • UPPSC
    • Banking
      • IBPS PO Notification
      • IBPS Clerk Notification
      • SBI PO Notification
      • SBI Clerk Notification
      • SBI SO Notification
      • SBI Apprentice Notification
      • Canara Bank PO Notification
      • Indian Bank PO Notification
      • RBI Assistant Notification
      • RBI Office Attendant Notification
      • IBPS RRB Notification
      • IBPS RRB Office Assistant Notification
    • Govt Exams
      • Railway
      • SSC
    • Skilling
      • Coding
      • Spoken English
      • Stock Marketing
    • TET
      • APTET
      • CTET
      • DSSSB
      • Karnataka TET
      • Kerala TET
      • KVS
      • MPTET
      • SUPER TET
      • TNTET
      • TSTET
      • UPTET
    • Courses
      • Data Science Course
        • Data Science Malayalam
      • Full Stack Developer Course
        • Full Stack Development Malayalam
        • Full Stack Development Hindi
        • Full Stack Development Tamil
        • Full Stack Development Telugu
        • Full Stack Development Kannada
      • Stock Market Course
        • Stock Market Course in Malayalam
        • Stock Market Course in Tamil
        • Options Trading Course
      • Spoken English Course
        • Spoken English Course in Malayalam
        • Spoken English Course in Hindi
        • Spoken English Course in Telugu
        • Spoken English Course in Tamil
        • Spoken English Course in Kannada
      • Python Programming Course
      • Practical Accounting Course
      • Quantity Surveying Course
    • Others
      • GATE
      • MAT
      • KMAT
      • UPSC

    © 2021 Entri.app - Privacy Policy | Terms of Service