15. (TCO 2) Briefly describe what an Interface is and how it can be used in an o
ID: 3529238 • Letter: 1
Question
15. (TCO 2) Briefly describe what an Interface is and how it can be used in an object-oriented program. Provide example pseudocode showing how an IEBook Interface might be constructed. (Points : 18) 1. (TCO 2) Keeping in mind all object-oriented programming best practices, create a class for a Keyboard, with the following specifications: Specify two data members Default Constructor Overloaded Constructor which takes both data member values as input. Generate a unique identification number for each object instantiated from this class. Use a static data member to keep track of the identification number last assigned to an object so that duplications will not occur. Code the necessary portion of the class definition so as to support this requirement. Show a statement which instantiates an object of this class using the overloaded constructor. You do not need to provide any accessor/mutator methods or other methods. (Points : 22)Explanation / Answer
Please Check it out..It is as per your requeirment..
An Interface is templete which is completely abstract in nature.
It means it does not have any existance in real world.
Itcontains only the signatures of methods, properties, events or indexers. A class or struct that implements the interface must implement the members of the interface that are specified in the interface definition.
For example : Vehicle is an abstract concept in real world..A bike can be a vehicle and a car can also be a vehicle.
So here we can declare Vehicle as an Interface and Bike and Car class can implement this Interfece Vehicle.
Generally When a real world object depends on two or more abstract entities like vehicle then we declar those entities as interface otherwise if its only a single dependancy like previous example then we prefer abstract class rather than interfaces.
Like a situation when Class D depends on abstract entites like A ,B,C
Then we declar A,B,C as interface.
D should implement A,B,C
PseudoCode for IBook Interface
1 -- start
2--Interface IBook
2.1 -- Declare attributes
2.2 -- Declare Function signatures.(Only signetures not body)
3-- End Interfece IBook
4-- End
Code for Keyword Class Following Proper coding standard..in java
public class Keyword {
private String type;
private int defaultValue;
private static int objectId = 0;
public Keyword() {
super();
}
public Keyword(String type, int defaultValue) {
super();
this.type = type;
this.defaultValue = defaultValue;
}
public static int getObjectId() {
return objectId;
}
public static void setObjectId(int objectId) {
Keyword.objectId = objectId;
}
public static void main(String []args)
{
//instantiation of an Object of the class
Keyword input=new Keyword("int",1);
//assigning a unique Id
setObjectId(objectId+1);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.