// A type of creature in the sea public abstract class SeaCreature{ // Called to move the creature in its environment public abstract void swim(); // Attempts to breed into neighboring locations public abstract void breed(); // Removes this creature from the environment public abstract void die(); // Returns the name of the creature public abstract String getName(); } 3. In an class, some methods and constructors may be fully defined and have code abstract supplied for them while other methods are A class may be declared abstract abstract. for other reasons as well. For example, some of the instance variables in an class abstract may belong to classes. abstract 4. More specialized subclasses of an class have more and more methods defined. abstract Eventually, down the inheritance line, the code is supplied for all methods. A class where all the methods are fully defined is called a class. A program can only create objects of concrete concrete classes. An object is called an of its class. An class cannot be instance abstract instantiated. 5. Different concrete classes in the same hierarchy may define the same method in different ways. For example: public class Fish extends SeaCreature{ ... /** * Returns the name of the creature */ public String getName(){ return "Wanda the Fish"; } ... } public class Mermaid extends SeaCreature{ ... /** * Returns the name of the creature */ public String getName(){ return "Ariel the Mermaid"; } ... } C. Polymorphism 1. In addition to facilitating the re-use of code, inheritance provides a common base data type that lets us refer to objects of specific types through more generic types of references; in particular, we can mix objects of different subtypes in the same collection. For example: SeaCreature s = new Fish(...); ...
// A type of creature in the sea public abstract class SeaCreature{ // Called to move the creature in its environment public abstract void swim(); // Attempts to breed into neighboring locations public abstract void breed(); // Removes this creature from the environment public abstract void die(); // Returns the name of the creature public abstract String getName(); } 3. In an abstract class, some methods and constructors may be fully defined and have code supplied for them while other methods are abstract. A class may be declared abstract for other reasons as well. For example, some of the instance variables in an abstract class may belong to abstract classes. 4. More specialized subclasses of an abstract class have more and more methods defined. Eventually, down the inheritance line, the code is supplied for all methods. A class where all the methods are fully defined is called a concrete class. A program can only create objects of concrete classes. An object is called an instance of its class. An abstract class cannot be instantiated. 5. Different concrete classes in the same hierarchy may define the same method in different ways. For example: public class Fish extends SeaCreature{ ... /** * Returns the name of the creature */ public String getName(){ return "Wanda the Fish"; } ... } public class Mermaid extends SeaCreature{ ... /** * Returns the name of the creature */ public String getName(){ return "Ariel the Mermaid"; } ... } C. Polymorphism 1. In addition to facilitating the re-use of code, inheritance provides a common base data type that lets us refer to objects of specific types through more generic types of references; in particular, we can mix objects of different subtypes in the same collection. For example: SeaCreature s = new Fish(...); ...