⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 flea.java

📁 Java2入门经典第二章源码
💻 JAVA
字号:
public class Flea extends Animal implements Cloneable
{
  // Constructor
  public Flea(String aName, String aSpecies)
  {
    super("Flea");                      // Pass the type to the base
    name = aName;                       // Supplied name
    species = aSpecies;                 // Supplied species
  }

  // Change the flea's name
  public void setName(String aName)
  {
    name = aName;                       // Change to the new name
  }

  // Return the flea's name
  public String getName()
  {
    return name;
  }

  // Return the species
  public String getSpecies()
  {
    return species;
  }

  public void sound()
  {
    System.out.println("Psst");
  }

  // Present a flea's details as a String
  public String toString()
  {
    return super.toString() + "\nIt's " + name + " the " + species;
  }

  // Override inherited clone() to make it public
  public Object clone() throws CloneNotSupportedException
  {
    return super.clone();
  }

  private String name;                      // Name of flea!
  private String species;                   // Flea species
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -