Glossary
@Override Annotation
A Java annotation used to indicate that a method in a subclass is intended to override a method in its superclass, helping the compiler detect errors if the method signature doesn't match.
Example:
When creating a custom toString() method in a Dog class, adding the @Override annotation above it ensures it correctly replaces the default Object class's toString().
Class
A blueprint or template for creating objects, defining their common attributes (instance variables) and behaviors (methods).
Example:
The Student class defines what every student object will have, like a name and grade level, and what actions they can perform.
Constructor Call (this())
A specific use of the `this` keyword within a constructor to invoke another constructor of the same class, facilitating code reuse and constructor chaining.
Example:
In a Circle class, this(5.0) inside a no-argument constructor Circle() could call Circle(double radius) to set a default radius, demonstrating a constructor call.
Constructor Overloading
The practice of defining multiple constructors within the same class, each with a different set of parameters (different number, type, or order), to provide various ways of initializing an object.
Example:
A Book class might have one constructor Book(String title, String author) and another overloaded constructor Book(String title) that sets a default author.
Instance Variable
A variable declared within a class but outside any method, constructor, or block, representing an attribute unique to each object (instance) of that class.
Example:
In a Student class, private String name; is an instance variable because each student object has its own unique name.
Local Variable
A variable declared inside a method, constructor, or block, whose scope is limited to that specific block of code.
Example:
In public void setAge(int newAge), newAge is a local variable that only exists within the setAge method.
Method Call (this.methodName())
Using the `this` keyword to explicitly call another method belonging to the same object from within one of its own methods.
Example:
Inside a Player object's calculateScore() method, this.updateDisplay() could be used to ensure the display is updated by calling another method of the same player object.
Object
An instance of a class, representing a real-world entity with its own unique state (values of its instance variables) and behavior (methods).
Example:
When you create Student s1 = new Student("Alice", 10);, s1 is an object of the Student class.
final keyword
A keyword used to declare a variable as a constant (its value cannot be changed after initialization), a method as unable to be overridden, or a class as unable to be extended.
Example:
Declaring private static *final* double PI = 3.14159; ensures that the value of PI cannot be altered throughout the program.
static keyword
A keyword used to declare members (variables or methods) that belong to the class itself rather than to any specific instance of the class, meaning they can be accessed directly via the class name.
Example:
The Math.random() method is static because you call it directly on the Math class, not on an object of Math.
this keyword
A special keyword in Java that refers to the current object, allowing access to its instance variables and methods, or to call other constructors within the same class.
Example:
When a Car object calls car.start(), inside the start() method, this refers to that specific car object.