1. (TCO 2) Keeping in mind all object-oriented programming best practices, creat
ID: 3645939 • Letter: 1
Question
1. (TCO 2) Keeping in mind all object-oriented programming best practices, create a class for a Mouse, 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
class Keyboard {
static int objcount=0;
int data1,data2;
int objid;
public Keyboard()
{
data1=0;
data2=0;
objid=objcount;
objcount++;
}
public Keyboard(int v1,int v2)
{
data1=v1;
data2=v2;
objid=objcount;
objcount++;
}
}
//end of definition
//statement for instantiation
Keyboard k=new Keyboard(5,4);
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.