What is An Abstract Class?
By veladitya
@veladitya (82)
India
March 9, 2007 4:25am CST
Abstract Class in java? Y it is used ?How it is Used? when it has to be used?
3 responses
@jhawithu (1070)
• India
20 Apr 07
A class that contains the common features of components of several classes, but cannot it be instantiated by itself. It represents an abstract concept for which there is no actual concrete expression. For instance, "mammal" is an abstract class - there is no such real, concrete thing as a generic mammal.
@eminaren86 (106)
• India
10 Mar 07
a class that is missing definitions for one or more methods.its like a class which has method declaration in it but the methods are not defined.so we cant create objects for that class.in order to create objects first we have to create subclass for that class and in it we have to define those methods that are declared in abstract class.in this way abstarct class works
@raghwagh (1527)
• India
10 Mar 07
An abstract class in java is a special type of class which contains one or more abstract methods (methods with no body and only signature).Thus an abstract class contains both normal and abstract methods.It is used if you want some normal methods and want to override some methods in the derived class.Abstract class cannot be instanciated thus for using abstract calss we have to create a derived class from the abstract class and then override the abstract methods.Also we can have the referance of derived class in the abstract class referance and access the normal methods from the abstract class.
example
//abstract class
public abstract class AbstractClassExample{
public void normalMethod()
{
System.out.println("In Normal Method");
}
public void abstractMethod();
}
//derived class
public class AbstractUse extends AbstractClassExample
{
public void abstractMethod()
{
System.out.printn("In abstract method");
}
public static void main(String args[])
{
AbstractClassExample ae=new AbstractUse();
ae.normalMethod();
ae.abstractMethod();
}
}
Hope this will help.