014-008-003
Object Class Inheritance: toString() Method
Easy
Problem Description
Object class inheritance: toString() method
In this problem, you will create a program that overrides the toString() method of the Object class in a Person class to return a formatted string as [Name: name, Age: age] and displays the result to standard output.
Learning Objective: Understand all classes inherit from Object and override toString()
override Object class toString() method to customize string representation of object.
Input
Line 1: Name
Line 2: Age
Output
[Name: name, Age: age]
Example
Input:
Taro
25
Output:
[Name: Taro, Age: 25]
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