Consider a superclass Course and three subclasses: ComputerScience, Math and Eng
ID: 3527218 • Letter: C
Question
Consider a superclass Course and three subclasses: ComputerScience, Math and English. What instance data and methods should be declared in Course and in each of the three subclasses? Come up with at least 1 instance data unique to each of the four classes. Recall that all instance data of Course will be inherited by the subclasses. Also, come up with the accessor and mutator methods for each class. You only have to provide their signatures, you do not have to provide the code for these methods. Be sure to include a one-line description for each instance data and method to explain what they do.Explanation / Answer
ach class program describes the behavior of two different objects: The class object The instances of the class There is never more than one occurrence of each type of class object in an application, whereas there can be many occurrences of its instances. If you are unsure of this point, review the Objects and Messages Tutorial. The main function of any class object is to create instances, although in some cases a class object has other behavior as well. A class program is structured as a set of nested programs (see Figure 11-1). The outermost level of the class program contains the data and behavior for the class itself. It can include one or more methods, each of which is a smaller program containing the code for one method. Figure 11-1: Class program structure The code block below shows the outline of an example class. An ellipsis (...) shows where code has been omitted, and indentation indicates the levels of nesting. class-id. Example inherits *> Class identification. from Base. *> Also sets up any *> data inheritance (none *> in this example). environment division. *> Environment division *> header is optional. *> All sections legal in *> MF or ANSI 85 COBOL *> environment division *> are valid, though not *> shown here. ... object section. *> Section containing OO *> specific environment *> information. class-control. *> Class control paragraph *> names the files *> containing the *> executables for each *> class. Example is class "exmp" *> The executable for the *> Example class is in *> file exmp. Base is class "base" CharacterArray is class "chararry" . *> Period terminates paragraph. data division. *> Data division header is *> optional. *> All sections legal in *> MF or ANSI 85 COBOL *> data division are valid, *> though not shown here. ... working-storage section. ... class-object *> Defines the start of the class *> object. object-storage section. *> Defines class object data ... ... method-id. "new". *> Start of class method "new". ... end method "new". *> End of class method "new". end class-object. *> End of the class object object. *> Start of the code *> defining behavior *> of instances *> of the class. object-storage section. *> Defines instance data. ... method-id. "sayHello".*> Start of instance *> method "sayHello" ... end method "sayHello".*> End of instance method. end object. *> End of code for *> instances. end class Example.