hey,
i am unable to understand the practical implementation of Abstraction in Java. Will you please explain and implement Abstraction with a suitable and simple example.
Printable View
hey,
i am unable to understand the practical implementation of Abstraction in Java. Will you please explain and implement Abstraction with a suitable and simple example.
See the link below...
Let me google that for you
Abstract classes all share one useless quality:
They cannot be 'instanciated' into an object.
You can create an abstract class by placing
within any class an incomplete method. When you
do this the compiler will complain that either
a method has be found that does not implement
code, and you should either add some code or
make the class abstract.
So, you decide to make it asbtract just for kicks.
We are back at the original question: what good
is it?
Here is one purpose.
An abstract classe is used as a 'blueprint' of the
type of object someone would like someone else
to create. Think of it as a management tool
which informs a programmer how to begin the
design of an object he is assigned to complete.
Think also of a team of programmers being assigned
to work from the same blueprint (extend from the
same abstract class.) All of these programmers
will be forced to adopt certain variables and
methods within the abstract class, bringing a certain
order to the project and making management happy.
Some programmers find abstract classes useful
for organizing their thoughts before commiting
to specific code.
Another use for an abstract class on a smaller
scale is for some who have the forsight to see
that common parts of several objects can
be grouped together. For example, an abstract
class "Animal". All animals can move, eat, reproduce,
are self-aware, etc. The Animal.class should not
specify how an animal will move, but it can contain
X, Y, Z coordinated of its position. Classes extended
from "Animal" can specify movement methods
like swim(), fly(), crawl(), etc. to update the
X, Y, Z values within its abstract core.
This last example sounds a lot like inheritence.
I think it is.
I'll have to remind myself to investigate if there
is any difference here.
a very good explanation..
so, it means that abstract classes and abstraction(pillar of Java) are same..
is abstraction is implemented in terms of abstract classes?
As far as I understand, abstraction in OOP languages such as Java is a very general concept, and while abstract classes allow for one type of abstraction, they are not equivalent of abstraction nor interchangeable. There are other ways to accomplish abstraction than abstract classes and in fact several types of categories of abstraction possible. Wikipedia has a decent article on this.
Cross posted
Abstraction (Beginning Java forum at JavaRanch)
db
I see how a suffix can make a difference.
Still, I hope I scored much higher than if
I advised the OP to search Google
for a "Java Abstract Example."
EDIT:
I've just scanned through several sites
on Abstract vs. Abstraction and found
almost no difference in the two, But I
thought the investigation was the
responsible thing to do.
Why am I bothering with this edit?
Because terminology can become
confusing in Java. For example, "final"
and "finally" must be approximately the
same topic in Java right? Wrong, of
course. Or maybe "Graphic User's Interface"
might be some form of "Interface," but
it's not.
I learned somethings new in my investigation.
There is always study to be found in the
details of a subject.
When I see a request to make a
topic clear, using plain terms, I think
some contributors show a lack of
consideration when advising someone
to "look it up on Google." Odds are
they already have, and possibly they
have found too much information, and
it all looks very confusing, or they are
following the wrong leads.
The educated programmers who review
this site know, eventually, when
they are being shnookered into doing
more work than is neccesary when
providing help.