• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Bear Bibeault
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Jj Roberts

Enacpusaltion In Java can anybody explain with small practical example

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

This is Anurag Pathak.

I have one doubt regarding OOPS Concept.

Can Any body explain Encapsulation in Java how it is achived through small practical example.

Looking forward for reply.

Thanks & Regards

Anurag Pathak

pathak_arg@yahoo.com

 
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Anurag Pathak wrote:Can Any body explain Encapsulation in Java how it is achived through small practical example.



In principle any class is an example. When you encapsulate something you get an inside and an outside and that's what happens when you introduce a class. The outside is called a data abstraction or the type. Hidden inside is the implementation.

The class allows you define a little "capsule" with specific properties you think it should have. People can use it without having to bother about how it works inside.

But also primitives like int and double, etcetera, are examples of encapsulation. It's just that they're readymade. The class concept (including enum) allows you to create your own "capsules".
 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Anurag Pathak wrote:
Can Any body explain Encapsulation in Java how it is achived through small practical example.


A simple pojo class with some getter and setters. Represents Encapsulation.

Difference from Abstraction.
list is an List object. So the User doesn't know about the inner implementation details of List
But we can perform many actions with this object. Like:-
So the List class is capsuled with these Methods.

Where as while using it in our programs we are abstracting those methods.Unaware of the inner details.

So we can say Abstraction is achieved by encapsulation.
 
Marshal
Posts: 71098
292
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Vivek Singh wrote: . . . So we can say Abstraction is achieved by encapsulation.

Very loose use of words there; since abstraction and encapsulation are different it would be better to say that good encapsulation helps abstraction.
 
Stop it! You're embarassing me! And you are embarrassing this tiny ad!
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic