Q1. Write an application that performs each of the following tasks: a) Specify that class “Pieceworker” inherits...

60.1K

Verified Solution

Question

Programming

Q1. Write an application that performs each of the followingtasks:

a) Specify that class “Pieceworker” inherits from classEmployee.

b) Create instance variables “Firstname” and “ID” in superclassand a toString to display.

c) Add “branch” and toString in PieceWorker.

d) Show overriding to display the variables of the subclass.

Q2 Draw an inheritance hierarchy for students at auniversity.

  • Use Student as the superclass of the hierarchy, and then extendStudent with classes Undergraduate Student and GraduateStudent.
  • Continue to extend the hierarchy as deep (i.e., as many levels)as possible. For example, freshman, sophomore, Junior and Seniormight extend undergraduate Student, and Doctoral Student andMasters Student might be subclasses of graduate Student.
  • After drawing the hierarchy, discuss the relationships thatexist between the classes.
  • Write a program that illustrates the above idea ofhierarchy.

Answer & Explanation Solved by verified expert
3.8 Ratings (395 Votes)
Q1 class Employee String Firstname ABC int ID 123 values hadcoded here can be used through constructor as well void show SystemoutprintlnFirstname ID Override public String toString return Employee Firstname Firstname ID ID class PieceWorker extends Employee String branch CSE Employee emp new Employee Override void show first way of overriding and showing superclass variables here We can reassign the value of one of the variables of superclass as well for eg String FirstnameDEF    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students