0% found this document useful (0 votes)
28 views

CSE 331 Assignment Midterm

Assignment for bubt

Uploaded by

sohailshaikh4612
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

CSE 331 Assignment Midterm

Assignment for bubt

Uploaded by

sohailshaikh4612
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Bangladesh University of Business & Technology (BUBT)

Department of Computer Science and Engineering


Mid-Term Assignment: Fall 2024
Course Code: CSE 331 │Course Title: Advanced Programming
Intake: 50, Shift: Day

Due– 07/10/2024 Marks –10


[Answer all the questions in handwritten offset]
SLN Questions
1. a) Design a solution to implement inheritance and polymorphism according to
following.
➢ Create 2 child classes (Teacher and Student) and parent class (Person).
➢ Inside parent class add one variable called age.
➢ Inside parent class add two methods one called showType to print “This is
a person”. Add another method for setting name called setAge() to set age
for objects.
➢ Override the showType() method inside both Student and Teacher classes
to print “This is a student” for student and “This is a teacher” for teacher
objects.
➢ Create Test class, then inside this class, create a student object and call
showType() method on the created object. Then call setAge() method to
set 25 as an age for that object.
➢ Use the appropriate access modifiers for methods and variables.

b) Can an interface itself be treated as a data type, and if so, how does this affect the
design and use of interfaces in your program? What happens if two unrelated
interfaces are implemented in one class but have the same method signature?

2. a) Explain the concept of method overloading where you will try to print the area
of various polygons such as circle and rectangle. Here the method area() must
be overloaded with different numbers of parameters. The output should look
like this.
b) What happens if class Z does not provide its own implementation of the show() method?

interface A {
void display();
}

interface B {
void display();
}

public class C implements A, B {


public static void main(String[] args) {
C obj = new C();
obj.display();
}
}

c) You are tasked with managing a collection of different musical instruments in a digital band
simulator. Each instrument should have the ability to perform its unique sound when played. There
are several types of instruments, including string, percussion, and wind instruments. In this
scenario, you need to design a system that allows these instruments to perform in sequence.
• The challenge is to manage these different instruments in a uniform way, ensuring that
each performs correctly when instructed, without needing to know the specific type of
instrument beforehand.

You might also like