Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java OOP encapsulation. Why is Object.doSomething(); better than doSomething(Object);?

Tags:

java

oop

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?

like image 334
user1114 Avatar asked Feb 02 '12 18:02

user1114


People also ask

Why is encapsulation important in object oriented programming?

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 is the concept of encapsulation in OOP?

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.

What is encapsulation in object oriented programming with examples?

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.

What are the examples of object oriented programming?

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.


1 Answers

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.

like image 168
kitti Avatar answered Nov 15 '22 09:11

kitti