this

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   go to next page

Answer:

The same names as can be used for variables (and methods and classes.)

this

Parameter names follow the same rules as the other names you might pick for a program. Names of this type are called identifiers. The rules for identifiers are given in chapter 9. Here is an altered definition of our HelloObject class:

class HelloObject                                  
{
  String greeting;

  HelloObject( String greeting )
  {
    this.greeting = greeting;
  }

  void speak()                                     
  { 
    System.out.println( greeting );
  }
}

The parameter is named greeting, a legal and sensible name. But the instance variable is also named greeting. This is OK, but can lead to some confusion. To avoid confusion, use the reserved word this to show when an identifier refers to an object's instance variable.

QUESTION 23:

What type of constructor would a class named Boa have?