0% found this document useful (0 votes)
8 views2 pages

Java Printer Class Implementation

The document defines a Java class structure for a Printer and a PrinterCumScanner that inherits from Printer. It includes constructors for initializing printer objects and overrides the toString method for customized output. The main method creates an array of printers and prints their details to the console.

Uploaded by

Hima's Ujumaki
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

Java Printer Class Implementation

The document defines a Java class structure for a Printer and a PrinterCumScanner that inherits from Printer. It includes constructors for initializing printer objects and overrides the toString method for customized output. The main method creates an array of printers and prints their details to the console.

Uploaded by

Hima's Ujumaki
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

//Creating class Printer

class Printer {

String companyName = "EPSON";


int pagesOutput = 40;
double price = 89.50;
//Constructor with no variables
public Printer() {}
//Constructor with variables
public Printer(String companyName, int pagesOutput, double price) {
//Initialization
[Link] = companyName;
[Link] = pagesOutput;
[Link] = price;
}
@Override
public String toString(){
return ([Link] +" having "+[Link] +" pages output and
priced "+[Link]);
}
}
//Class PrinterCumScanner inheriting properties from Printer
class PrinterCumScanner extends Printer {

private int imageDPi = 320;


//Constructor with No variables
public PrinterCumScanner() {}
//Constructor with variables
public PrinterCumScanner(String companyName, int pagesOutput, double price, int
imageDPi) {
//Initialization
super(companyName, pagesOutput, price);
[Link] = imageDPi;
}
@Override
public String toString(){
return [Link] +" having "+[Link] +" pages output priced
"+[Link] + " and "+[Link]+" DPi";
}

public class PrinterClient {

public static void main(String[] args) {

//constant number of printer


final int NUM_PRINTER = 3;
//array of printer
Printer[] store = new Printer[NUM_PRINTER];
store[0] = new Printer("HP", 40, 89.50);
store[1] = new PrinterCumScanner("Cannon", 30, 175.0, 240);
store[2] = new PrinterCumScanner("Nikkon", 50, 215.0, 360);

for (Printer obj : store) {


[Link](obj);
}
}
}

You might also like