Creating the talk() Method for the CritterTalk Program

Take a look at the next version of the Critter program, Critter Talk. This version is on the CD-ROM as CritterTalk, if you want to look at the entire program.

class Critter {

  public string name;
  public void talk(){
    Console.WriteLine("The Critter says: My name is {0}", name);
  } // end talk

} // end class

I added a method named talk() to the Critter class. The method is very simple. It sends a message to the screen. Note that, inside the method, the program refers to the name variable. It can do this because both the name variable and talk() method belong to the Critter class.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.35.194