011-002-003
Constructor Overloading: Person Class
Easy
Problem Description
Constructor Overloading: Person Class
Learning Objective: Understand how to define multiple constructors with different arguments
Define two constructors in Person class: one with no arguments and one with arguments. Choose the appropriate constructor based on situation.
Input
Line 1: Name (string)
Line 2: Age (integer)
Output
Default: Unknown, 0 years
Custom: [name], [age] years
Test Cases
※ Output examples follow programming industry standards
Input:
Taro 25
Expected Output:
Default: Unknown, 0 years Custom: Taro, 25 years
Input:
Hanako 30
Expected Output:
Default: Unknown, 0 years Custom: Hanako, 30 years
Input:
Baby 0
Expected Output:
Default: Unknown, 0 years Custom: Baby, 0 years
❌ 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
