Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Discuss whether land improvements are eligible for cost recovery.

Answered: 1 week ago

Question

What are the advantages and disadvantages of flextime?

Answered: 1 week ago

Question

What could Kathy have done to keep the situation from occurring?

Answered: 1 week ago

Question

How can Seaview improve their benefits communication? Discuss.

Answered: 1 week ago