group-icon
Java Developers
Group for Java developers and programmers. Ask questions and get answers related to Java programming
270 Members
Join this group to post and comment.
Gaurav Prasad
Gaurav Prasad
Computer Science
15 Jan 2019

Explain Encapsulation Oops concept for java language?

how is it different from polymorphism ?

Archana Priyadarshini
Archana Priyadarshini
Computer Science
4mos ago

Encapsulation is a principle of wrapping data and code together as a single unit. It keeps the data and the code safe from external interference. In encapsulation, the variables of a class are hidden from any other class and can be accessed only through any member function of own class in which they are declared.

Polymorphism is the ability of an object to take on many forms. It is the capability of a method to do different things based on the object that it is acting upon. In other words, polymorphism allows you define one interface and have multiple implementations.The most common use of polymorphism in OOP occurs when a parent class reference is used to refer to a child class object. 

DHIRAJ LOTLIKAR
DHIRAJ LOTLIKAR
Information Technology
4mos ago

Encapsulation is the process of combining all of the object's attribute and methods into a single package. It encapsulates the data means hiding information so that other classes should not alter an object's attributes. Other classes should not be allowed to make a request that an attribute be altered. For example the car driver not able to see the burning of fuel, working of engine etc. but he can see the brake, steering wheel etc.

The world is full of objects. So polymorphism means in many forms is that the idea that has function or method. For example the open method for a door is different for the open method for the drawer.

You will find java code examples online and after running you will understand it properly.

Gaurav Prasad
Gaurav Prasad
Computer Science
4mos ago

Thanks for your answers.