I am struggling to explain oop concepts in java.
A major tenet in oop is that objects have methods; so Object.method(); works. I am contrasting this with procedural programming in which one must do method(Object).
Is this called encapsulation?
What are the advantages of the oop way?
Encapsulation is one of the fundamentals of OOP (object-oriented programming). It refers to the bundling of data with the methods that operate on that data. Encapsulation is used to hide the values or state of a structured data object inside a class, preventing unauthorized parties' direct access to them.
What does encapsulation mean: In object-oriented computer programming (OOP) languages, the notion of encapsulation (or OOP Encapsulation) refers to the bundling of data, along with the methods that operate on that data, into a single unit. Many programming languages use encapsulation frequently in the form of classes.
In Object Oriented Programming, Encapsulation is defined as binding together the data and the functions that manipulates them. Consider a real life example of encapsulation, in a company there are different sections like the accounts section, finance section, sales section etc.
Significant object-oriented languages include Java, C++, C#, Python and Javascript. The simplest way to explain object-orientated programming to a kid is to use something like a car as an example.
That's a big question with an answer that fills multiple books, but in short, class members have access modifiers (public, private, protected). Private members can be accessed by other class members, such as a method, but not from external functions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With