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

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).

his "concept of the abstract class" is flawed if he believes it's what lies at the heart of interfaces...

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

Edited 6 Years Ago by tong1: n/a

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.

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.

Edited 6 Years Ago by coil: n/a

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.

This article has been dead for over six months. Start a new discussion instead.