Question

In: Computer Science

(Java) Please describe how API's can be created using abstract classes, interfaces and regular classes.

(Java) Please describe how API's can be created using abstract classes, interfaces and regular classes.

Solutions

Expert Solution

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


Related Solutions

7. What are abstract classes and interfaces in Java? What are they used for, and what...
7. What are abstract classes and interfaces in Java? What are they used for, and what are they comprised of? Clearly explain the difference between the two.
java programming You will be given two interfaces and two abstract classes, FileTextReader, FileTextWriter, AbstractFileMonitor, and...
java programming You will be given two interfaces and two abstract classes, FileTextReader, FileTextWriter, AbstractFileMonitor, and AbstractDictionary. Your job is to create two classes the first class should be named FileManager, the second class should be named Dictionary. The FileManager will implement the interfaces FileTextReader and FileTextWriter and extend the clas AbstractFileMonitor. Your class signature would look something like the following: public class FileManager extends AbstractFileMonitor implements FileTextReader, FileTextWriter{... The constructor signature of the FileManager should look like the following:...
java programming You will be given two interfaces and two abstract classes, FileTextReader, FileTextWriter, AbstractFileMonitor, and...
java programming You will be given two interfaces and two abstract classes, FileTextReader, FileTextWriter, AbstractFileMonitor, and AbstractDictionary. Your job is to create two classes the first class should be named FileManager, the second class should be named Dictionary. The FileManager will implement the interfaces FileTextReader and FileTextWriter and extend the clas AbstractFileMonitor. Your class signature would look something like the following: public class FileManager extends AbstractFileMonitor implements FileTextReader, FileTextWriter{... The constructor signature of the FileManager should look like the following:...
What are abstract classes? What are interfaces? What is the difference?
What are abstract classes? What are interfaces? What is the difference?
What are similarities and differences between abstract classes and interfaces? What are the default modifiers of...
What are similarities and differences between abstract classes and interfaces? What are the default modifiers of their methods and variables? What are allowed modifiers of their methods and variables? Essay Question
create scientific calculator using java language with OOP rule and interfaces.
create scientific calculator using java language with OOP rule and interfaces.
Graphical User Interfaces using java. Please provide proper commenting so that I understant what is going...
Graphical User Interfaces using java. Please provide proper commenting so that I understant what is going on in the program: Develop a simple tool for analyzing a segment of text that determines the number of words in that segment and the average word length. The application should have a single window with a scrolling text box (JTextArea) and an area to display the statistics. The statistics area should be a panel with a titled border, containing labeled fields that display...
Java Programming Please describe the roles of the following classes in processing a database: Connection ResultSet
Java Programming Please describe the roles of the following classes in processing a database: Connection ResultSet
IN JAVA Question 1 The following classes along with the driver has been created and compiled....
IN JAVA Question 1 The following classes along with the driver has been created and compiled. public class Car { public void method1() { System.out.println("I am a car object"); } } class Point { public void method2() { System.out.println("I am a Point object"); } } class Animal { public void method3() { System.out.println("I am an animal object"); } } The following driver class has been created and all the lines of code inside the for loop is not compiling. Modify...
HELLO CAN YOU PLEASE DO THIS JAVA PROGRAM WITH THE DIFFERNT CLASSES LISTED BELOW. I WILL...
HELLO CAN YOU PLEASE DO THIS JAVA PROGRAM WITH THE DIFFERNT CLASSES LISTED BELOW. I WILL LEAVE AWESOME RATING. THANK YOU IN ADVANCE. The code needed for this assignment has to somehow implement a stack interface (including a vector stack, array stack, and a linked stack). The classes needed are the Game class, the disk class, the driver, and the stack interface (including arraystack, linkedstack, and vectorstack) QUESTION Suppose you are designing a game called King of the Stacks. The...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT