Practice Questions for Mid
Practice Questions for Mid
Class
class Animal {
void sound() {
A regular blueprint to create objects.
System.out.println("Animal sound");
Can have both properties and methods (with full implementation). }
Can use inheritance (one class can extend another). }
Abstract Class
interface Animal {
void sound(); // no body
Relationship with Inheritance: }
Summary:
Practice Questions for Midterm
1.
1. Define an interface `Product` with methods `String getProductName()` and `void produce()`. [2]
2. Create a class `CentralLocking` implementing the `Product` interface: [3]
- Add a private property `String productName`
- Implement the constructor to initialize `productName`.
- Define `getProductName()` to return the product name.
- Define `produce()` to print "Producing Central Locking System".
C. In the TestClass:
→ Create 2 object of PersonalTask and 2 objects of ProfessionalTask, initializing them with
appropriate values.
Example:
Personal Task : Losing 5kg, Ocotber.
Professional Task: Being pro in programming, December
→ Call all the methods using the objects created.
→ At the end update all the task to complete state and call displayStatus() to check the task
update.
3.
Implementation Details:
● Use an interface named Individual which contains the methods printDetails() and calculate(). 4
● Create an abstract class named Person which implements the Individual interface, has the
common properties name and age and has Constructors to initialize them. 4
● Create concrete classes Doctor and Patient that extend the Person abstract class,
implementing the additional methods and properties. 4
● Create another class named HospitalManagement that contains the main method. 1
● Take input from the user the details of the following three different doctors and initialize the
objects using constructors. 2
○ name="Dr. Smith", age=35, specialization="Cardiology", yearsExperience=8,
patientsTreated=600, visitAmount=1200, outdoorHours=20
○ name="Dr. Johnson", age=38, specialization="Neurology", yearsExperience=10,
patientsTreated=820, visitAmount=1400, outdoorHours=18
○ name="Dr. Green", age=42, specialization="Gynecology", yearsExperience=15,
patientsTreated=1300, visitAmount=1500, outdoorHours=20
● Take input from the user the details of four different patients and initialize the objects using
constructors. 2
○ name="Alice Wilstone", age=20, disease="Flu", visitAmount=400, testAmount=1000,
wasAdmitted=false
○ name="Bob Nielsen", age=35, disease="Diabetes", visitAmount=1200,
testAmount=8000, wasAdmitted=true
○ name="Jake Peralta", age=56, disease="Heart disease", visitAmount=2000,
testAmount=1200, wasAdmitted=true
○ name="Emma Stone", age=45, disease="Cancer", visitAmount=500,
testAmount=1500, wasAdmitted=true
● Calculate the amount of bonus Dr. Johnson should receive by invoking the appropriate 1
methods.
● Mr. Nielsen has visited the hospital and paid 2000 taka as doctors visit and spent 10000 taka for
the test. Update his total bill invoking appropriate methods. 1
● Calculate the percentage of discount Mr. Nielsen should receive by invoking the appropriate
Method. 1