CSE1115 Mid 182
CSE1115 Mid 182
There are THREE questions. Figures in the right-hand margin indicate full marks.
1. (a) Write a code fragment to create the following multidimensional integer array. (2)
(d) Explain what is wrong with this code. Fix the code. You CANNOT add/delete any line. (3)
2. (a) How many objects are eligible for garbage collection after executing the following code (show graphically)?(3)
(b) Write a complete Product class implementing encapsulation. The class has the following instance variables:
name, price. Use getter and setter methods in the class to set and get the values of the fields. However,
ensure that name and price cannot be changed from outside of the class. Write a constructor to initialize
the Product object with name only. (3)
(c) Write the output of the code. (4)
3. (a) Suppose youre building a software for a private organization. Now, write a class named Employee. It has
two attributes name and salary with types respectively String and Floating point number. The constructor
of Employee class initializes name and salary with this reference keyword. There is one method named
void printSalary(). The classes that extend Employee are PlatinumEmployee and SilverEmployee.
PlatinumEmployee class overrides printSalary() method by invoking parent method and also prints the
name and bonus amount which is 15% of the actual salary and finally prints the total salary by adding the
bonus amount. SilverEmployee class also overrides printSalary() in similar way except that the bonus
amount is 7% in this case. Write the code of these two classes also. (4)
(b) Write the output of the code. (3)