" Learn Free Coding contains well written, well thought, well explained and easily Understandable computer science articles, Learn C, Java, Python, HTML, C# & everything else. "

Object Oriented Programming (oops) Concepts

oops-img
oops concept

 

What is the purpose of Data Hiding?

 

 • Data hiding is mistaken as data security. 

 •By hiding data a programmer can avoid mishandling of data by the code outside the class. 

 • Data is accessible only within a class.

 • Only the functions of a class, knows what processing should be done on that data 


  Encapsulation vs Abstraction 

 •A Class is used for Encapsulation as well as Abstraction 

 •Encapsulation means combining related data members and functions together. 

 • Encapsulation is achieved using a class. 

 • Abstraction means hiding data and showing required functions. 

 •Abstraction is achieved using encapsulation and data hiding. Private and public. 

  structure vs class

C++ supports both structure and class  

 • structure in C++ can have data members and member functions. 

 •All members of a structure are public by default. 

 • class can contain data members and member functions 

 •All members of a class are private by default.

  What is “this” pointer?

 It represents current object. 

 • It is useful in avoiding variable name conflict. 

 Example for current object. 

class Test{ 

private: 

 int value; 

public: 

void fun(int x){

 this->value=x;

 } 

}; 

int main(){

 Test t1,t1; // both t1 and t2 are having “value” 

t1.fun(10); // “this” inside fun means “value” of t1. 

t2.fun(20); // “this” inside fun means “value” of t2. 

Example for variable name conflict.

 class Test{ 

 private:

 int value; 

public: 

void fun(int value){

 // here parameter name and data member name is same “value” to access data member “this” is used. this->value=value; 

 }

}

Object Oriented Programming (oops) Concepts Object Oriented Programming (oops) Concepts Reviewed by Shaishav Anand on June 15, 2021 Rating: 5

3 comments:

  1. Apollo Medical Ptv Ltd is here to provide you affordable medical billing services around the globe. Our trained and certified coding specialist are here to help you provide medical billing soultions. Get our services today!

    medical billing and coding

    ReplyDelete
  2. Java Nested For Loop with Simple Example
    Read Now

    ReplyDelete
  3. Nice Blog! I really loved reading through this Blog... Thanks for sharing.......
    Awesome Blog thanks for share your valuable information

    Inwizards Technology - Internet of Things IoT

    iot development company
    hire iot developer

    ReplyDelete

Powered by Blogger.