Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Objects (Retired) Harnessing the Power of Objects Methods and Constants

Jan-Philippe Emmanuel Rasay Guerrero
Jan-Philippe Emmanuel Rasay Guerrero
1,567 Points

Java Objects

These GoKarts have a single rechargeable battery that have a display of bars to measure its energy level. Each battery has a maximum of 8 bars.

For this task, let's add a constant field to the class that stores the maximum number of energy bars. Make sure the field cannot be changed and is accessible from the class, not just the instance. Use the naming convention we learned.

1 Answer

Let's understand this problem step by step.All hints are provided in problem statement. <ul> <li>1. Use final keyword ( Hint - Make sure the field cannot be changed)</li> <li>2. Use public & static keyword (Hint - is accessible from the class, not just the instance ) </li> <li>3. Use Upper Case letter's for defining constants (Hint - Use the naming convention )</li> </ul>

public static final int GO_KART= 8 ;

This will be solution to above problem.i used "GO_KART" for variable name.You can use any name as you wish.I use underscore for my naming conventions because if you see JAVA API documentation then you will observe that most system defined constant are use _ (underscore) in between to word.