PrepAway - Latest Free Exam Questions & Answers

Which code segment should you use?

You are developing a custom event handler to automatically print all open documents.
The event handler helps specify the number of copies to be printed.
You need to develop a custom event arguments class to pass as a parameter to the event handler.
Which code segment should you use?

PrepAway - Latest Free Exam Questions & Answers

A.
public class PrintingArgs {
private int copies;
public PrintingArgs(int numberOfCopies) {
this.copies = numberOfCopies;
}
public int Copies {
get {return this.copies;}
}
}

B.
public class PrintingArgs : EventArgs {
private int copies;
public PrintingArgs(int numberOfCopies) {
this.copies = numberOfCopies;
}
public int Copies {
get {return this.copies;}
}
}

C.
public class PrintingArgs {
private EventArgs eventArgs;
public PrintingArgs(EventArgs ea) {
this.eventArgs = ea;
}
public EventArgs Args {
get {return eventArgs;}
}
}

D.
public class PrintingArgs : EventArgs {
private int copies;
}

Explanation:
The event handler will require a parameter of type EventArgs or a derived type. The derived type in this example will question states that the event handler helps specify the number of documents that require printing,
this information will have to come from the derived EventArgs class in the form of an instance variable.
A & C do not derive from EventArgs hence cannot fit into the event handling model.
D does not expose the copies instance variable.

One Comment on “Which code segment should you use?


Leave a Reply