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
Java assignment, abstract class, inheritance, and polymorphism. these are the following following classes: Animal (abstract) Has...
Java assignment, abstract class, inheritance, and polymorphism. these are the following following classes: Animal (abstract) Has a name property (string) Has a speech property (string) Has a constructor that takes two arguments, the name and the speech It has getSpeech() and setSpeech(speech) It has getName and setName(name) It has a method speak() that prints the name of the animal and the speech. o Example output: Tom says meow. Mouse Inherits the Animal class Has a constructor takes a name and...
in java Create the classes SubstitutionCipher and ShuffleCipher, as described below: 1. SubstitutionCipher implements the interfaces...
in java Create the classes SubstitutionCipher and ShuffleCipher, as described below: 1. SubstitutionCipher implements the interfaces MessageEncoder and MessageDecoder. The constructor should have one parameter called shift. Define the method encode so that each letter is shifted by the value in shift. For example, if shift is 3, a will be replaced by d, b will be replaced by e, c will be replaced by f, and so on. (Hint: You may wish to define a private method that shifts...
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...
create scientific calculator using java language with OOP rule and interfaces.
create scientific calculator using java language with OOP rule and interfaces.
create calculator standard using java language with OOP rule and interfaces.
create calculator standard using java language with OOP rule and interfaces.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT