Question: The following table describes the required instance variables for two classes and typical values stored in those variables. As a java programmer, you need to
The following table describes the required instance variables for two classes and typical values stored in those variables. As a java programmer, you need to create a super class Printer and its sub class PrinterCumScanner. Each of these classes should have parameterized constructor and overridden toString() method so that the following test driver can work properly. Object Orientated Programming Java
| Class | Instance variables | Typical values for instance variables |
| Printer | companyName, pagesOutput, price | HP, 40, 89.50 |
| PrinterCumScanner | imageDpi and all the instance variables of Printer | 320, instance variables value of printer |
public class PrinterTest
{ public static void main(String[ ] args)
{
// constant for number of Printers final int NUM_PRINTERS = 3;
// array of Printers. Printer [ ] stock= new Printer [NUM_PRINTERS];
stock [0] = new Printer (HP,40, 89.50);
// PrinterCumScanner is a sub class of Printer stock [1] = new PrinterCumScanner (HP,40,215.0,320);
stock [2] = new PrinterCumScanner (Cannon,30,175.0,240);
//print details of Printers for( Printer aPrinter: stock)
System.out.println(aPrinter);
} }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
