This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes a very Basic OOP Doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "a very Basic OOP Doubt" Watch "a very Basic OOP Doubt" New topic
Author

a very Basic OOP Doubt

Bhairava Surya
Ranch Hand

Joined: Aug 19, 2007
Posts: 45
Hi All,

I have few queries on basic Object Oriented programming concepts.

I have done proper home work. I searched in net. but I am not satisfied with the answers i got. So I am posting this query?

In many places I have seen. this concepts means
1) Inheritance
2) Polymorphism
3) Encapsulation

then what abt abstraction???

a) What are the the actu properties?
b) Its only the first 3 or it also includes abstraction??
c) Also I read some where abstraction means hiding implementation? is this true? if so where are we hiding the implementation exactly. even in a pure abstract class we dont have any implementations. Please explain me with proper example?
d)Why people try to differentiate abstratcion and encapsulation? as both are different topics. as i know no where they are related. please explain with some real time example.

Hoping for a quick response.

Thanks in anticipation.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
Welcome to JavaRanch.

A lot of big questions, actually. I shall try to answer a few.

The real idea behind object-oriented (OO) programming is that you create software "objects" which have data (called fields in Java) and behaviour (called methods in Java).
You can have a few objects or you can have as many as you can fit onto your computer's memory (I once tried and go to 6000000, but I didn't examine them individually!) Objects can communicate with one another; they send "messages" which tell other objects to do something. In Java we call those messages method invocations.

A class represents an abstraction; a Car class might have speed and colour, but you can't tell what colour the Car class is, nor what speed it is travelling at. [This is different from an abstract class; forget abstract classes for the moment.]
An object is also called an instance of its class; you can have a Car object which records it is "red" and travelling at 60mph.

The class encapsulates all that, colour, speed, going faster, stopping, etc. It includes code to do all those things. It is a good idea to keep the data hidden so other objects can only reach them via methods, and to hide the way things are worked out (data hiding).

I hope that helps as a start, and I hope other people will have their own answers to add.
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

Welcome to JavaRanch...


Also I read some where abstraction means hiding implementation? is this true? if so where are we hiding the implementation exactly.

As another example of this, let's say I have a FinancialApplication class that uses a method double(int x) from a Calculator class from another package or another API. How that method doubles the number is hidden from me. The FinancialApplication class doesn't know (or care) if it is doing x + x or x * 2. It's hidden.



Why people try to differentiate abstraction and encapsulation? as both are different topics. as i know no where they are related. please explain with some real time example.


Mr Google has a lot to say on this subject, including this JavaRanch post.


As a side note, please UseRealWords when posting. Thanks.
[ July 10, 2008: Message edited by: Mark Vedder ]
Bhairava Surya
Ranch Hand

Joined: Aug 19, 2007
Posts: 45
Hi,

Thanks for the immediate response.

I am just confirming my understanding. Please correct me if I am wrong.

1) If we are talking about OOPs principle means, we should speak about all the four principles, i.e including abstraction also.

2) This concept of abstraction is no where related to abstract class or interface. When I am talking about abstraction means its different from abstract class.

3) In Java, Classes use the concept of abstraction, by defining a list of attributes and methods that operate on these attributes.

Please correct me regarding these points.
I have few more points to discuss once these are confirmed.

Thanks
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
Only a few questions?

Yes, you are correct in your last post . . . but it's late and I am off to bed . . .

I hope somebody else will answer.
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
When I think of abstraction, I like to use the Car analogy also. Not a car class, but an actual automobile. I'm no mechanic. I know very little about how a car runs under the hood. I do know how to get unlock a car door, get in, start the car, and control the speed and direction of the car with the accelerator, brake, steering wheel, gear shift, and clutch. Information hiding has a lot to do with it, I don't have to worry about pistons firing and crankshafts and the like, I know the harder i press on the accelerator, the faster I'll go. If I turn the wheel right, the car will veer right.


I can get into a rental car I've never driven before and be confident that I'll be able to navigate it to my destination. The abstraction of a car helps me in two ways to accomplish this. First off, by hiding all the gory details of the car's operation, I can worry about the important stuff like not hitting the other cars, and stopping a all the red lights. Secondly, since all car manufacturers have settled on a pretty consistent abstraction for operating a car, I know where the steering wheel is and what it does, and how to put the car in reverse even in a car I'm just driving for the first time.

If all manufacturers had a different operating abstraction, say if you accelerated with hand levers and steered with your feet in a BMW, and you could steer a Ford by leaning left/right and go faster by wiggling a joystick, then the common abstraction is lost. There are still abstractions there, but without a standard they make each driving experience unique.

I hope in all my rambling you may have picked up some little nugget of information.


Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
 
wood burning stoves
 
subject: a very Basic OOP Doubt
 
Similar Threads
OOPS Concepts - Redefined(Confirmation required)
Articles on OOP
OOP Concepts
Abstraction and Encapsulation
Doubts in Basic Concepts of OOPS