Abstract Class
§ Abstract class is a class which can not be instantiated, which is declared by abstract keyword.
§ Abstract class may or may not contain abstract methods. Abstract method is a method which is declared without any implementation. Abstract methods cannot be marked as final or abstract private. Abstract modifier can never be combined with static modifier.
§ Abstract class contains one or more concrete methods and instance variables. Abstract class can have private or protected methods and variables.
§ Abstract class provides tight coupling.
§ If a class includes abstract methods, the class itself must be declared abstract.
§ Abstract class is subclassed. Subclass provides the implementation for all the abstract methods in the parent class. If it does not provide implementations for all the abstract methods it must be declared as abstract.
§ Abstract class may have static methods and static variables. We can access this static members using class reference i.e. AbstractClassDemo.staticSample();
§ Can only subclass one abstract class. Single inheritance is achieved through the abstract class.
§ Abstract class can extend only one superclass but it can implement more than one interface.
§ The general form of abstract class is
____________________________________________
public abstract class Programmer {
private int i=0
public String str=”hello”;
public abstract void program();
public int getdata(){//code}
}
____________________________________________
Interface :
§ Interface are pure abstract class. Interface are just like classes, but doesn't contain instance variables and methods are declared without any body.
§ Java interface are designed to support dynamic method resolution at runtime.
§ All the methods in the interface are by default public abstract.
§ Interface contains constants, all variable are by default public static final.
§ The class which is implementing the interface must provide the actual implementation.
§ A class can implement more than one interface. Multiple inheritance is achieved through the interface.
§ Interface can extend more than one interface.
§ The general form of interface is
interface name{
return-type method-name(parameter-list);
type final-varname= value;
}
Here name is interface name. Note that method which are declared don't have method body.