+ 3

The data is not directly accessible to the outside world but function are accessible to the outside world why?

1st May 2017, 2:37 AM
Nikhil
Nikhil - avatar
2 ответов
+ 12
Basic OOP concept : Data Encapsulation. Real life example: You dont need to know how the electric circuit works when you switch on the Bulb. You just need to know that the Bulb will be ON when the switch is ON. The switch is a function and the electric circuit is the data This is used to prevent the user from knowing unwanted complicated stuff that may have no implications to them. This is why data is stored in functions and functions are accessed by objects
1st May 2017, 2:40 AM
Pixie
Pixie - avatar
+ 1
But remember one thing... Data values or Functions are visible to outside world as per requirement... using various keywords like public, private or protected... there may be a case when a data value or a function needs to be completely confined within the scope of a class... or should be available to the super class...! Outside world itself is a layered structure so you need to be precise ,which world you are talking about...means you should be aware about the multilevel inheritance and different packaging configuration of your projects.
1st May 2017, 5:14 AM
Abhishek Kumar
Abhishek Kumar - avatar