011-002-009
Calling Constructors
Easy
Problem Description
Calling Constructors
In this problem, you will create a program that defines a constructor with arguments in the Person class, reads a name and age from standard input, initializes fields upon object creation, and displays a self-introduction to standard output.
Learning Objective: Understand how to define and call constructors
Overview
Define a constructor that takes arguments and initialize during object creation.
Specifications
- Define constructor Person(String name, int age) in Person class
- Initialize fields and output self-introduction with introduce() method
- Read name (line 1) and age (line 2) from standard input, create instance with new Person(name, age)
Input Format
name
age
Output Format
I am {name}, {age} years old.
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