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
Studentclass - Define a
Stringfieldnameand anintfieldscore(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
nameis"Alice",scoreis85: returns"Alice: 85"nameis"Bob",scoreis92: 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