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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started