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

João Ignácio Brito
João Ignácio Brito
1,201 Points

Reviewing lines

Are the comments that I've put about the code correct?:

class PezDispenser{
  /*
  public = Public variable
  static = It can be initialized without instanciating an object
  final = It can only be defined once
  int = Variable of integer tipe
  MAX_PEZ ==> Shows that it's a constant value;Capital letters and words spread by underline
  */
  public static final int MAX_PEZ = 12;//Maximum number of pez
  final private String characterName;//Name of the character
  private int pezCount;//Number of pez inside

  public PezDispenser(String characterName) {
    this.characterName = characterName;
    pezCount = 0;
  }//Class with name of the character and quantity of pez when It's created

  public String getCharacterName() {
    return characterName;
  }//Returns private variable without allowing the user to modify it



public class Example {
/*
public:acces level modifier
void:It does not return anything
static:It can be initialized without instanciating an object
*/
  public static void main(String[] args) {
    // Your amazing code goes here...
    System.out.println("We're making a new PEZ Dispenser");
    System.out.printf("FUN FACT: There are %d PEZ allowed in every dispenser %n",
                      PezDispenser.MAX_PEZ);//Inictializing variable without instanciate the object
    PezDispenser dispenser = new PezDispenser("Yoda");//Instanciating object
    System.out.printf("The dispenser is %s %n",
                      dispenser.getCharacterName()
                     );

  }

}

2 Answers

Everything looks pretty good, but

public PezDispenser(String characterName) { this.characterName = characterName; pezCount = 0; }//Class with name of the character and quantity of pez when It's created

this is not actually a class it's the constructor. A constructor is similar to a method, but yeilds no return. The constructor is just initializing those member variables for an object of the class. Constructors always have the same name as the class.

João Ignácio Brito
João Ignácio Brito
1,201 Points

Ohh thats correct. Thanks for the answer!