In: Computer Science
(Java) Please describe how API's can be created using abstract classes, interfaces and regular classes.
Interfaces:
Interfaces won't have method implementation but only method declaration. All the methods in interfaces are pub;ic abstract (default). Some class has to inherit the interface and define the implementation of the method.
eg: Interface Car { void PrintColor(); void PrintNumberOfGears();}
Public class BlueCar implements Car
{
public void PrintColor() {System.out.println("Color is Blue");}
public void PrintNumberOfGears() {System.out.println("Number of Gears are 5");}
}
Abstract Class:
Abstract Methods are similar to normal classes but it can have abstract as well as concrete methods. Abstract methods has to be inherited and defined.
example : public abstract class Students
{
public void PrintMarks() {System.out.println("Printing Marks");} //concrete method
public abstract void PrintEmpId { } //abstract method
} //Note the abstract keyword
Regular Classes:
Regular classes cannot have abstract methods , but only concrete methods. See the above abstract class example and take only the concrete method. as an example.
eg: public class Employee{}
APIs are also methods. So all of the above discussed details are good for creating APIs