014-003-005

super Keyword: Extending Parent Method

Medium

Problem Description

super Keyword: Extending Parent method

In this problem, you will create a program that reads a brand name and model name from standard input, calls the parent class Vehicle's start() method from the child class Car using the super keyword to extend its functionality, and displays the result to standard output.

Learning Objective: Understand how to call parent class methods using super keyword

Overview

The super keyword is used to call parent class methods or constructors from child classes. This allows extending parent class functionality.

Specifications

Create parent class Vehicle:

  • Private field brand
  • constructor accepts brand
  • start() method: outputs "Vehicle starting"
  • getBrand() method: returns brand

Create child class Car:

  • Extends Vehicle
  • Private field model
  • Constructor accepts brand and model
  • override start(): call parent's start() then output "Car engine ready"
  • getInfo() method: returns brand and model

In Main class:

  • Read brand name from line 1 of standard input
  • Read model name from line 2 of standard input
  • Create Car instance
  • Call start()
  • Call getInfo() and output

Input Format

{brand}
{model}

Output Format

Vehicle starting
Car engine ready
Brand: {brand}, Model: {model}

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