Glossary
Abstraction
The process of hiding complex implementation details and showing only the essential features of an object. It focuses on what an object does rather than how it does it.
Example:
When you use a remote control, you're using abstraction; you press a button to change the channel without needing to know the complex electronic signals involved.
Diamond Problem
A classic ambiguity that arises in programming languages that support multiple inheritance, where a class inherits from two parent classes that share a common ancestor, leading to uncertainty about which inherited method implementation to use.
Example:
Java avoids the diamond problem by disallowing a class from directly inheriting from more than one superclass.
Dynamic and Static Typing
Static typing refers to type checking at compile-time, while dynamic typing refers to type checking at runtime. In Java, variables have a static type (declared type) and an object has a dynamic type (actual type).
Example:
If you declare Animal myPet = new Dog();, Animal is the static type, and Dog is the dynamic type of myPet.
Inheritance
A mechanism in OOP where one class (subclass) acquires the properties and behaviors (methods and instance variables) of another class (superclass). It promotes code reusability and establishes an 'is-a' relationship.
Example:
A Car class might inherit from a Vehicle class, meaning a Car is a Vehicle and automatically gets properties like speed and color from Vehicle.
Method Overriding
A feature that allows a subclass to provide a specific implementation for a method that is already defined in its superclass. The method signature (name, parameters) must be the same.
Example:
A Cat subclass might override the makeSound() method inherited from Animal to specifically print "Meow!" instead of a generic sound.
Object-Oriented Programming
A programming paradigm based on the concept of 'objects', which can contain data and code. It emphasizes principles like inheritance, polymorphism, abstraction, and encapsulation.
Example:
In a game, you might use Object-Oriented Programming to model different types of characters, like a Player object and an Enemy object, each with their own properties (health, score) and behaviors (move, attack).
Polymorphism
The ability of an object to take on many forms, allowing an object to be called by its own class type or by its superclass type. It enables a single interface to represent different underlying forms.
Example:
You could have a list of Animal objects, but some might be Dogs and others Cats; calling the makeSound() method on each will result in different sounds due to polymorphism.
Subclass
A class that inherits properties and methods from another class (its superclass). It is also known as a child class or derived class.
Example:
If Vehicle is a superclass, then Car and Motorcycle would be subclasses, inheriting common vehicle characteristics.
Superclass
A class whose properties and methods are inherited by other classes. It is also known as a parent class or base class.
Example:
In a hierarchy where Dog and Cat are types of Animal, Animal would be the superclass.
The Object Superclass
The `Object` class is the root of the class hierarchy in Java; every class implicitly inherits from it. It provides basic methods like `equals()`, `hashCode()`, and `toString()`.
Example:
Even a simple MyClass you create implicitly inherits from Object, meaning you can call myObject.toString() without explicitly defining it.
The super Keyword
A keyword used in a subclass to refer to members (constructors, methods, or instance variables) of its immediate superclass.
Example:
Inside a Dog subclass constructor, **super**("Buddy") might call the Animal superclass constructor to set the animal's name.
extends keyword
A keyword used in Java to indicate that a class is inheriting from another class, establishing an inheritance relationship.
Example:
public class Dog **extends** Animal { ... } shows that Dog is a subclass of Animal.