flea.java
来自「Java2入门经典第二章源码」· Java 代码 · 共 49 行
JAVA
49 行
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 + =
减小字号Ctrl + -
显示快捷键?