Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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.