zuai-logo

Glossary

D

Diamond problem

Criticality: 2

A problem that arises in programming languages supporting multiple inheritance, where a class inherits from two parent classes that both inherit from a common grandparent class. This creates ambiguity when a method defined in the grandparent is overridden in both parent classes, making it unclear which version the inheriting class should use.

Example:

If Shape is a grandparent, and Circle and Square are parents inheriting from Shape (each with a draw() method), a class ColoredShape trying to inherit from both Circle and Square would face the diamond problem regarding which draw() method to use.

I

Inheritance

Criticality: 3

A fundamental principle in object-oriented programming where a new class (subclass) can acquire the properties and behaviors (methods and instance variables) of an existing class (superclass). This promotes code reusability and establishes an 'is-a' relationship.

Example:

In a game, a Knight class might inherit from a Character class, automatically gaining basic attributes like health and attack power.

S

Subclass

Criticality: 3

A class that derives from another class (the superclass), inheriting its methods and instance variables. It can also introduce its own unique methods and variables, making it a more specific type of the superclass.

Example:

If Vehicle is a superclass, then Motorcycle would be a subclass, inheriting general vehicle properties but adding specific motorcycle features like hasSidecar.

Superclass

Criticality: 3

A class whose properties and behaviors are inherited by one or more other classes (subclasses). It represents a more general or broader category from which more specific classes are derived.

Example:

In a hierarchy of electronic devices, Appliance could be a superclass for Refrigerator and Toaster, providing common traits like powerConsumption.

e

extends keyword

Criticality: 3

A Java keyword used in a class declaration to specify that the class being declared is a subclass of another class. It establishes the inheritance relationship, allowing the subclass to inherit members from the superclass.

Example:

To make a Cat class inherit from an Animal class, you would declare public class Cat **extends** Animal { ... }.