It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming Java Forum

what is the difference between Encapsulation and Abstraction

what is the difference between Encapsulation and Abstraction

Postby reply4konda on Thu Apr 05, 2007 12:45 pm

What is the difference between Encapsulation and Abstraction,Tell me real time examples.
reply4konda
 
Posts: 3
Joined: Wed Mar 28, 2007 12:56 pm
Location: pune

Postby ggomez on Tue Apr 17, 2007 4:05 am

Encapsulation is when you can use diferents tool from a single object in your program.

for example: Obj o=new Obj();
o.sum(); o.divide() and everything inside the same object.

Abstraction is when you simplify a complicate proccess with a few statement.

for example: o.solveEquation(2,3,5)

with this i wont need to complicate my life every time i need it.

it is encapsulated because its inside an object and its abstract beacause i dont really need to know how to resolve equations.

A good tutorial will do a better job, this is to make the understanding easier.
ggomez
 
Posts: 45
Joined: Tue Apr 17, 2007 3:30 am
Location: !!!!!MéXiCo¡¡¡¡¡¡

Postby skoiloth on Wed May 09, 2007 11:25 am

Abstaction is selective ignorance where in if you come across a common functionlaity in in any system which differs in some of details which are specific to those particular objects and overall most of the functionlait is common.. So you abtact out all such common functionlaity and put it in one place and just change the functionlaity for specifics. Go through the very draw ,shape , rectangle example from any basic book..

class Person {
private final Date birthdate = ...;

long calculateAge() {
return System.currentTimeMillis() - birthdate.getTime();
}
}



Simplified, this would rather be encapsulation.
skoiloth
 
Posts: 6
Joined: Wed May 09, 2007 9:51 am


Who is online

Users browsing this forum: No registered users and 1 guest