007-003-010
Pet Greeting Program
Easy
Problem Description
Pet Greeting Program
In this problem, you will define a Cat class with a name field, a constructor that takes a name, a greet() method that prints a greeting, and a getName() method that returns the name.
Learning Objective: Understand field definitions, constructor initialization, and method invocation
Overview
Create a Cat class where each cat has a name and can greet. Learn how fields, constructors, and methods work together.
Specifications
- Define a
Stringfieldnamein theCatclass - Initialize the name via a
Cat(String name)constructor - The
greet()method outputsMeow! I'm <name>. - The
getName()method returns the name
Output Example
When creating Cat("Tama") and calling greet():
Meow! I'm Tama.
Hints
- Assign the constructor argument to the field
- Use string concatenation to include the name in
greet()
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