Question: Q.1 a) Differentiate between abstract class and an interface. Briefly explain when we use abstract class and interface in any project? (5) b) Write

Q.1 a) Differentiate between abstract class and an interface. Briefly explain when

Q.1 a) Differentiate between abstract class and an interface. Briefly explain when we use abstract class and interface in any project? (5) b) Write the code of the following scenario. (9) Create an abstract class Worker that has instance variables name and age. Create a parameterized constructor that initialized these instance variables. Create getter and setter of each instance variable. Write a method Output which should use the getter methods of each variable to show the value of each instance variable. In worker class add an abstract method Calculate Payment having double return type. Create Hourly Worker class that inherits Worker class having instance variables price and hours of data type int. Create getters for both instance variables. Create a parameterized constructor in such a way that it should initialized data members of this class as well as parent class. Create setter for price in such a way that it should not accept negative values. Create setter for hours in such a way that it should accept values from 0 to 30 only. Complete CalculatePayment method by price multiply by hours. Override Output method in this class also in such way that it should call first parent class Output and then use the getter method of each instance variable to show the value of each instance variable. Create a class name Driver having main method. Create an object of child class and test all possible functions. Ans. Write your answer here

Step by Step Solution

3.41 Rating (154 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Differentiate between abstract class and interface A Abstract class Abstract class has a concrete bo... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!