943,800 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 4320
  • Java RSS
Sep 26th, 2007
0

need of abstract class

Expand Post »
i know the concept of abstract class in java and this concept is used in interface, i.e all the methods declared in interface are abstract. i want to know how the abtract class is different from the normal class in java

Thanks a million
Similar Threads
Reputation Points: 37
Solved Threads: 0
Newbie Poster
tinamary is offline Offline
16 posts
since May 2007
Sep 26th, 2007
0

Re: need of abstract class

I'm sorry, but if you "know the concept of abstract class", then you know how it "is different from the normal class".

Maybe we should begin with you stating what you believe to be "the concept of abstract class", and what you believe to be "the normal class". Then we can continue on.

The most basic difference, of course, is that you cannot instantiate the abstract class, directly. That does not mean that you cannot get an instatiated object declared as an abstract type, but you cannot directly instantiate the abstract class (except anonymously, in which case it is still not really a direct instantiation of the abstract class as it will be "extended" inline, i.e. the methods are defined on instantiation).
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Sep 26th, 2007
0

Re: need of abstract class

his "concept of the abstract class" is flawed if he believes it's what lies at the heart of interfaces...
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Aug 27th, 2010
0

pls do to ma question

pls explain the concept of abstract classes and method in java............
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mansi4u is offline Offline
1 posts
since Aug 2010
Aug 27th, 2010
0
Re: need of abstract class
Normal class:
Normal class has definition of methods and variables and their declaration as well.
Abstract class:
Abstract class has methods and variables with definition and declaration as well like the normal classes. Hoewever it must have at least one method with no implementation, which hence is called abstract method.
We can not make instance of Abstract Class.
Interface:
Interface is an "extreme" abstract class where all the methods are abstract, that is, all methods with no implementation.

Reference:
Normal class vs Abstract class vs Interface class 65
Last edited by tong1; Aug 27th, 2010 at 4:29 am.
Reputation Points: 34
Solved Threads: 72
Posting Whiz
tong1 is offline Offline
358 posts
since Jul 2010
Aug 27th, 2010
0
Re: need of abstract class
abstraction is the act of representing essential features withi=out including the background details or explaination. so, abstraction is used for hiding the unnecessary or the unwanted data from being displayed. for example if you know about functions in java, the process of calling the sub function,etc is hidden from the user. in a normal class, all these processes are shown.
Reputation Points: 10
Solved Threads: 3
Newbie Poster
Megha SR is offline Offline
24 posts
since Jul 2010
Aug 27th, 2010
0
Re: need of abstract class
In terms of actual functionality, an interface usually represents an ability, and an abstract class typically has a 'is-a' relationship with subclasses.

For example:
You might have an interface Drivable, and classes Car and Bus that implement it, because both Cars and Buses are Drivable.

You might also have a Machine abstract class, and a class Computer that extends it, because a Computer is-a Machine.
Last edited by coil; Aug 27th, 2010 at 5:11 pm.
Reputation Points: 27
Solved Threads: 56
Posting Whiz in Training
coil is offline Offline
273 posts
since Aug 2010
Aug 27th, 2010
0
Re: need of abstract class
There is actually a significant difference between the abstract class and the interface. The abstract class depends on inheritance, while there is no inheritance in implementing an interface.

An interface simply says "I can do these things". It is a promise to the compiler that a method that implements this interface will have a certain set of methods, which take certain parameters and return certain types. It says nothing about how those methods should be implemented. You might have a "sortable" interface which requires that something sort itself. When you go to implement this method, you get to and you have to implement it each time - this is good because it can be anything at all, and there's no guarantee that sorting your Car class will be anything like sorting your Fencepost class. So this doesn't require anything but "the stuff in this class will be in order when we're done".
This is a drag, if you have a lot of things that are the same, and you want them to sort themselves the same way. Suppose you have a VWBug class and a Miata class and an Edsel class. All of these will be sorted in the same way, presumably - perhaps by VIN or license plate number, or I don't know what, but they'll all sort in the same fashion. So here's where you use an abstract class. You make a class Car, which is abstract - it exists only to be extended - but it extends "Sortable" and it has a fully implemented sort() method, which is suitable for any class extending Car. Now, when you extend Car, you get the sorting for free, and you're automatically registered as implementing Sortable.

Understanding inheritance and interfaces is very important to making Java work for you. I sugest you do some reading on this, and then write little programs to test what you read, until you get the hang of it. Just reading what we all say about here will not be enough to understand it.
Reputation Points: 383
Solved Threads: 186
Posting Virtuoso
jon.kiparsky is offline Offline
1,837 posts
since Jun 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Random # generator from -1 to 1
Next Thread in Java Forum Timeline: How can new webservice connect to an already running application ?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC