1.

A superclass Worker has been defined to store the details of a worker. Define a subclass Wages to compute the monthly wages for the worker. The details/specifications of both the classes are given below: Class name: Worker Data Members/instance variables: Name: to store the name of the worker Basic: to store the basic pay in decimals Member functions: Worker (…): Parameterised constructor to assign values to the instance variables void display (): display the worker’s details Class name: WagesData Members/instance variables: hrs: stores the hours worked rate: stores rate per hour wage: stores the overall wage of the worker Member functions: Wages (…): Parameterised constructor to assign values to the instance variables of both the classes double overtime (): Calculates and returns the overtime amount as (hours*rate) void display (): Calculates the wage using the formula wage = overtime amount + Basic pay and displays it along with the other details Specify the class Worker giving details of the constructor () and void display ( ). Using the concept of inheritance, specify the class Wages giving details of constructor ( ), double-overtime () and void display (). The main () function need not be written.

Answer»

importjava.io.*; 

class worker

{ String Name; double Basic; 

public worker (String n, double b) 

{ Name = n; Basic = b; 

public void display ( ) 

System.out.println (Name); 

System.out.println (Basic); 

class wages extends worker 

int hrs, rate; 

double wage public wage (string n, double b, int h, int r, double w) 

super (n, b); 

hrs = h; 

rate = r; 

wage = w; 

public double overtime () 

return (hours*rate); 

public void display ( ) 

{ super.display (); 

wage = overtime () + Basic; 

System.out.prinln(wages); 

}



Discussion

No Comment Found

Related InterviewSolutions