1 line
970 B
Markdown
1 line
970 B
Markdown
One example that I think works pretty well is Pokémon. We can have a base Pokémon class with an "electric type Pokémon" subclass and then "Pikachu" subclass for a specific Pokémon. A base Pokémon superclass might have variables like number and name that subclasses will inherit. The "electric type Pokémon" subclass might add a "possible moves" field for electric type moves that the Pokémon can learn. The Pikachu class might then have specific height, weight, abilities, and could override functions like "make sound" or "get information." You can use the "electric type Pokémon" to reference any electric type Pokémon even though they might have different moves or abilities showing polymorphism. Each Pokémon class can also include functions for abilities and moves as well as traits like height, weight, and name for encapsulation. The base Pokémon class could have a "baseMove" abstract method that each subclass has to implement showcasing abstraction. |