Challenge: Add a Method to Your Class
In this challenge, you’ll build a class from scratch and give it behavior.
Your tasks
Create a class named
PlayerinsideMain.Inside
Player, add:a
Stringcallednamean
intcalledscore
Write a constructor that sets
nameandscorewhen aPlayeris created.Add a method called
display()that prints:name scored scoreIn
main():Create two
PlayerobjectsCall
display()on each one
Example output
Aria scored 50Luca scored 70
Hint
Constructors have the same name as the class
Use
this.nameandthis.scoreto store values inside the objectCall methods with:
objectName.methodName()
Challenge: Add a Method to Your Class
In this challenge, you’ll build a class from scratch and give it behavior.
Your tasks
Create a class named
PlayerinsideMain.Inside
Player, add:a
Stringcallednamean
intcalledscore
Write a constructor that sets
nameandscorewhen aPlayeris created.Add a method called
display()that prints:name scored scoreIn
main():Create two
PlayerobjectsCall
display()on each one
Example output
Aria scored 50Luca scored 70
Hint
Constructors have the same name as the class
Use
this.nameandthis.scoreto store values inside the objectCall methods with:
objectName.methodName()