Abstract methods

An abstract method is one with only a signature and no implementation body. It is often used to specify that a subclass must provide an implementation of the method. Abstract methods are used to specify interfaces in some computer languages.
Example
The following java code shows an abstract class that needs to be extended:
abstract class Main{ 
abstract int rectangle(int h,int w); //abstract method signature
}

The following subclass extends the main class:
public class Main2 extends Main{
@Override
int rectangle(int h,int w)
{
return h*w;
}
}


Post a Comment