018-003-002

Generic Storage Box

Easy

Problem Description

In this problem, you will implement the Box<T> class that manages object state through fields such as item. Create a generic Box<T> class that can store any type of object. Implement store(T item) to put an item and get() to retrieve it.

Test Cases

※ Output examples follow programming industry standards

Input:
new Box<>(); box.store("Hello"); box.get()
Expected Output:
Hello
Input:
new Box<>(); box.store(42); box.get()
Expected Output:
42
Input:
new Box<>(); box.get()
Expected Output:
null
Input:
new Box<>(); box.store(3.14); box.get()
Expected Output:
3.14
❌ Some tests failed
❌ エラー発生

Your Solution

Current Mode: My Code
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 1 free executions remaining