Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
Step: 1
Differentiate between abstract class and interface A Abstract class Abstract class has a concrete bo...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started