Wednesday, February 27, 2013

Difference between Abstract class and Interface

Abstract Class
==========
1.An abstract class can have method body (non-abstract methods).
2.An abstract class can have instance variables.
3.An abstract class can have constructor.
4.An abstract class can have static methods.
5.You can extends one abstract class.

ex:
publlic abstract class TxnCommand
{

public abstract void  show();

public void calculate()
{
//Method Implimentatiion;
}

}

Interface
=======
1.Interface have only abstract methods.
2.An interface cannot have instance variables.
3.Interface cannot have constructor.
4.Interface cannot have static methods.
5.You can implement multiple interfaces.

ex:


public
interface CommonCommand
{

public static final int i = 10;
public abstract void  show();

}

No comments:

Post a Comment