Glossary
Dynamic Typing
The concept where the actual method executed on an object is determined at run-time based on the object's actual type, rather than its declared type.
Example:
If Vehicle myVehicle = new Car();
is declared, calling myVehicle.startEngine()
will execute the Car
's specific startEngine()
method at run-time, demonstrating Dynamic Typing.
Inheritance
A core OOP principle allowing a new class (subclass) to acquire the properties and behaviors (methods and attributes) of an existing class (superclass), promoting code reuse and reducing duplication.
Example:
A SportsCar
class can inherit the accelerate()
and brake()
methods from a general Car
class, avoiding redundant code.
Inheritance Hierarchy
A structured set of classes connected by parent-child (superclass-subclass) relationships, where characteristics are passed down from parent to children, forming the basis of object-oriented design.
Example:
A diagram showing Electronics
at the top, with Computer
and Phone
as its children, and Laptop
as a child of Computer
, illustrates an Inheritance Hierarchy.
Method Overriding
The ability of a subclass to provide a specific implementation for a method that is already defined in its superclass, using the same method signature.
Example:
A Cat
class might perform Method Overriding on the makeSound()
method from its Animal
superclass to produce a "Meow!" instead of a generic animal sound.
Method Signature
The combination of a method's name and its parameter list (number, type, and order of parameters), which uniquely identifies the method within a class.
Example:
The method signature for public void processOrder(String item, int quantity)
is distinct from public void processOrder(int quantity, String item)
.
Object class
The root class in Java's class hierarchy; every other class implicitly inherits from it, providing fundamental methods like `equals()` and `toString()`.
Example:
Even a custom GameCharacter
class implicitly inherits from the Object class, gaining default implementations for methods like toString()
.
Object-Oriented Programming
A programming paradigm centered around objects, which are instances of classes, and their interactions. It emphasizes concepts like inheritance, polymorphism, encapsulation, and abstraction.
Example:
Designing a simulation where Robot
and Obstacle
are objects interacting within a virtual environment is a prime example of Object-Oriented Programming.
Polymorphism
An OOP principle allowing objects of different types to be treated as objects of a common type (their superclass), where the specific method executed depends on the object's actual run-time type.
Example:
If you have a list of Shape
objects that includes Circle
and Square
instances, calling draw()
on each will correctly render its specific shape due to polymorphism.
Static Typing
The concept where the type of a variable is checked at compile-time, and the methods that can be called on an object are determined by its declared type.
Example:
If Animal myPet = new Dog();
is declared, the compiler, through Static Typing, only knows myPet
as an Animal
, so it can only call methods defined in the Animal
class, even if Dog
has more specific ones.
Subclass
A class that is derived from a superclass, inheriting its methods and attributes and often specializing or adding new behaviors.
Example:
A Wizard
class is a subclass of Character
, inheriting basic stats but adding unique spell-casting abilities.
Superclass
A general class that serves as a parent or base class, providing common methods and attributes that its subclasses can inherit.
Example:
In a game, Enemy
could be the superclass for more specific types like Goblin
and Dragon
, defining shared behaviors like takeDamage()
.
equals() method
A method inherited from the `Object` class, often overridden in custom classes to define how two objects of that class are considered equal based on their content rather than just their memory addresses.
Example:
Overriding the equals() method in a Book
class allows you to compare two Book
objects based on their ISBN and title, not just if they are the exact same object in memory.
extends keyword
A Java keyword used in a class declaration to indicate that the class is a subclass of another class, thereby establishing an inheritance relationship.
Example:
The line public class ElectricCar *extends* Car {}
signifies that ElectricCar
is a specialized type of Car
.
super keyword (for constructors)
A Java keyword used within a subclass constructor to call the constructor of its immediate superclass, allowing the superclass's instance variables to be initialized.
Example:
Inside a Student
constructor, *super*(name, age);
calls the Person
class constructor to set the student's basic personal details.
super keyword (for methods)
A Java keyword used within a subclass method to call the overridden version of that method from its immediate superclass, allowing the subclass to extend or modify the superclass's behavior.
Example:
A PremiumAccount
's deposit()
method might call *super*.deposit(amount)
to handle the basic deposit, then add a bonus for premium users.
toString() method
A method inherited from the `Object` class, commonly overridden in custom classes to provide a human-readable string representation of an object's state.
Example:
Overriding the toString() method in a Player
class to return a string like "Player: [name], Score: [score]" makes debugging much easier.