007-001-014

Class Creation: Multiple Instances

Medium

Problem Description

Class Creation: Multiple Instances

In this problem, you will define a Student class with name and score fields, initialize instances via a constructor, and implement a getInfo() method that returns student information as a string.

Learning Objective: Understand how to create multiple instances from the same class, each holding independent data

Specifications

  • Create a Student class
  • Define a String field name and an int field score (package-private)
  • Implement a Student(String name, int score) constructor for initialization
  • Implement a String getInfo() method that returns "name: score" format

getInfo() Return Examples

  • name is "Alice", score is 85: returns "Alice: 85"
  • name is "Bob", score is 92: returns "Bob: 92"

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