You can refer the below YouTube Video in which I have explained the complete program. Example code is given below.
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
class Test
{
private:
int privateData;
public:
Test(int data1)
{
privateData = data1;
}
void display();
};
void Test::display()
{
printf("Value of private data = %d\n", privateData);
}
int main()
{
Test obj1(97);
printf("Before Change:\n");
obj1.display();
int *p = (int *) &obj1;
*p = 43;
printf("Violate the Object Oriented Programming Concept\n");
printf("After Change:\n");
obj1.display();
getch();
return 1;
}
Note:-
Accessing the private data using this type of algorithm is against Object Oriented Concept.
Related Post:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
class Test
{
private:
int privateData;
public:
Test(int data1)
{
privateData = data1;
}
void display();
};
void Test::display()
{
printf("Value of private data = %d\n", privateData);
}
int main()
{
Test obj1(97);
printf("Before Change:\n");
obj1.display();
int *p = (int *) &obj1;
*p = 43;
printf("Violate the Object Oriented Programming Concept\n");
printf("After Change:\n");
obj1.display();
getch();
return 1;
}
Note:-
Accessing the private data using this type of algorithm is against Object Oriented Concept.
Related Post:
0 comments :
Post a Comment