014-006-007

Field Access with super.

Easy

Problem Description

Field Access with super.

In this problem, you will create a program that uses the super. keyword to access fields with the same name in both the parent and child class, displaying each value to standard output.

Learning Objective: Understand how to explicitly access parent class fields using super.

Overview

Create a program that uses super. to access parent class field when child class has a field with the same name.

Specifications

  • Define protected String value field in Base class (initialized via constructor parameter)
  • Derived class extends Base and defines same-named protected String value field (initialized via constructor parameter)
  • In Derived constructor, call super(baseValue) to initialize parent class field
  • Create showValues() method in Derived to output both this.value and super.value
  • In Main.java, use Scanner to read 2 lines and pass them to the Derived constructor

Input

Base class value (line 1)
Derived class value (line 2)

Output Format

This value: <derived value>
Super value: <base value>

Ready to Try Running Code?

Log in to access the code editor and execute your solutions for this problem.

Don't have an account?

Sign Up