011-002-005
Constructor Invocation: Object Initialization
Easy
Problem Description
Constructor Invocation: Object Initialization
Learning Objective: Understand how to invoke a constructor to initialize an object
Overview
Create a Person class with a constructor that receives name and age, initializing the object at creation time.
Specifications
- Create a Person class
- Parameterized constructor: Person(String name, int age)
- Initialize fields within the constructor
Input
Name and age are provided
Output Format
Name: Taro
Age: 25
Test Cases
※ Output examples follow programming industry standards
Input:
Taro 25
Expected Output:
Name: Taro Age: 25
Input:
Hanako 30
Expected Output:
Name: Hanako Age: 30
❌ Some tests failed
Your Solution
Current Mode:● My Code
99
1
2
3
4
5
6
7
8
9
10
›
⌄
⌄
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Write your code here
sc.close();
}
}
0 B / 5 MB
You have 9 free executions remaining
