You are on page 1of 1

Bangladesh University of Business & Technology (BUBT)

Department of Computer Science and Engineering


Midterm Examination: Summer 2021
Course Code: CSE 331 │Course Title: Advanced Programming Language
Intake: 42, Program: B.Sc. Engineering in CSE

Marks – 30
[Answer all the questions]

CO1 1. a. Input an array of 10 integers from user. While traversing the elements of array by ‘for- [5]
each’ loop, add 5 to the odd elements and add 10 to the even elements.
Complete the program in Java.
b. Define a class named rectangle which has private data members length and width as [5]
integer type. A member method set_dimensions() is used to set the length and width
of an object. To calculate the area of the rectangle, a method named area() is used to
take an rectangle object as parameter and returns the area of the object. Now create
an object of rectangle class, then set the length and width of the object and show the
area as output. Discuss the impact of encapsulation in this program.

CO2 2. a. Discuss the relation between dynamic method dispatch and method overriding. [5]
Elaborate your answer with an appropriate example.
b. Write a program using three classes named Cricket, Football, and Badminton where [5]
the constructor of Cricket class takes two integer and one character value as argument.
And the other two classes Football and Badminton take one integer and one character
as argument. The constructors contain the message “In Cricket class”, “In Football
class” and in “In Badminton class” respectively.

Complete the above program considering the following case:

Football inherits Cricket and Badminton inherits Football. While implementing the
program, make it sure that the program reflects the significance of inheritance.

CO3 3. a. Now, using the above scenario of question 2b - [5]


Consider another case, “Cricket and Football are parent class and Badminton is child
class inherited from Cricket and Football”. Is the case valid? Justify your answer with
proper explanation. If not, then how can we solve this problem? Provide necessary
code to proof your statement.

b. Create an abstract class named Geometry. It will contain members such as height, [5]
width.

It will have abstract methods such as shape()

Now create these classes:


Square [here, height = width]
Rectangle

Here, classes Square and Rectangle inherit the abstract class Geometry and implement
the abstract method shape(). Complete the program.

You might also like