Question: Help to complete these questions! 1) A parent class named 'Pen' has a single constructor with a parameter of the Color data type. You are

Help to complete these questions!

1) A parent class named 'Pen' has a single constructor with a parameter of the Color data type. You are extending the Pen class to create a new class named 'GreenPen'. Complete the following code to create a default constructor for GreenPen that sets the color field of Pen to Color.GREEN. Note that Color.GREEN is a valid object of the Color class.

public GreenPen() { _______________________; }

2) You have a subclass named 'FancyPen' that extends the superclass 'Pen'. Both Pen and FancyPen have a public method named 'getFont' which has no parameters and returns an object of the Font class. Fill in the blank to complete a method in FancyPen named 'getDefaultFont' that passes the parent class's font value to the caller.

public Font getDefaultFont() { ____________________________; }

3) You have a subclass named 'VariableWidthPen' that extends the superclass 'Pen'. Pen has a protected method named 'setColor' that has a Color object as its only parameter. You want to make that method public in your VariableWidthPen class. Complete the following code to do so:

@Override public void setColor(Color color) { ______________________; }

Language:Java

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!