Category

Featured

Category

Understanding overloading and overriding in java is a cornerstone of object-oriented programming. Method overloading occurs when multiple methods in the same class have the same name but different parameters (compile-time polymorphism). In contrast, overriding happens when a subclass provides a specific implementation for a method already defined in its superclass (run-time polymorphism). Overloading is about versatility within a class, while overriding is strictly tied to inheritance.

Method overriding means a subclass provides its own implementation of a method that already exists in its parent class – same name, same parameters, same return type. The JVM decides which version to call at runtime based on the actual object type – this is runtime polymorphism. Overriding is only possible through inheritance.

What Is Method Overloading in Java?

Overloading allows a class to have multiple methods sharing the same name, as long as their parameter lists differ – either in the number of parameters, the types of parameters, or both. The return type alone cannot distinguish overloaded methods.

Think of it like a restaurant with a ‘serve’ function: serve(pizza), serve(pasta), serve(salad) all do the same general action but handle different inputs differently. The system picks the right one based on what you pass in.

What Is Method Overriding in Java?

Overriding happens when a child class redefines a method inherited from its parent. The overriding method must have the exact same signature – same name, same parameter types, and same (or covariant) return type. It cannot have a more restrictive access modifier than the parent method.

Think of it like this: a parent class Animal has a method makeSound(). The child class Dog overrides makeSound() to return ‘Woof’ instead of a generic sound. Same method name, different behaviour – determined at runtime by the actual object type.

Overloading vs. Overriding – Key Differences

Feature Method Overloading Method Overriding
Definition Same name, different parameters Same name, same parameters
Where it happens Same class Parent and child class
Polymorphism type Compile-time (static) Runtime (dynamic)
Inheritance required? No Yes
Return type Can differ Must be same or covariant
Access modifier Can be anything Cannot be more restrictive
Static methods Can be overloaded Cannot be overridden
@Override annotation Not used Recommended to use

Method Overloading – Code Example

Here is a simple Java class demonstrating method overloading:

public class Calculator {

// Method 1: adds two integers

public int add(int a, int b) {

return a + b;

}

// Method 2: adds three integers (different number of params)

public int add(int a, int b, int c) {

return a + b + c;

}

// Method 3: adds two doubles (different parameter type)

public double add(double a, double b) {

return a + b;

}

}

In this example, all three methods are named ‘add’ but the compiler knows which one to call based on the arguments passed. add(2, 3) calls method 1. add(2, 3, 4) calls method 2. add(2.5, 3.5) calls method 3. Clean, intuitive, and all resolved before the program runs.

Method Overriding – Code Example

Here is a Java example showing overriding in action:

public class Animal {

public void makeSound() {

System.out.println(“Some generic animal sound”);

}

}

public class Dog extends Animal {

@Override

public void makeSound() {

System.out.println(“Woof!”);

}

}

public class Cat extends Animal {

@Override

public void makeSound() {

System.out.println(“Meow!”);

}

}

When you call makeSound() on an Animal reference that holds a Dog object, Java calls the Dog version at runtime – not the Animal version. This is the power of runtime polymorphism: the actual behaviour depends on what the object really is, not what variable type holds it.

Rules to Remember

Rules for Overloading

Parameters must differ – either in number, type, or order. Return type alone is not enough to distinguish overloaded methods. Access modifiers can be different across overloaded versions. Static, final, and private methods can all be overloaded.

Rules for Overriding

The method signature must be identical to the parent method. The access modifier cannot be more restrictive (public parent method cannot be overridden as private). The overriding method can throw fewer or narrower checked exceptions, but not broader ones. Use the @Override annotation always – it catches mistakes at compile time. Static methods cannot be overridden – they can be hidden, which is a different concept.

Real-World Use Cases

Use Case Overloading or Overriding? Example
Printing different data types Overloading print(int), print(String), print(double)
Animal hierarchy sounds Overriding Dog.makeSound() vs Cat.makeSound()
Constructor variations Overloading Person(), Person(name), Person(name, age)
Payment processing types Overriding CreditCard.process() vs PayPal.process()
Math utility functions Overloading Math.abs(int), Math.abs(double)
UI component rendering Overriding Button.draw() vs ImageView.draw()

Common Mistakes Beginners Make

Thinking return type alone creates an overload: It does not. Java will throw a compile error if two methods have the same name and parameters but different return types.

Forgetting @Override: Without the annotation, if you misspell the method name in a subclass, Java will silently treat it as a new method – not an override. The @Override annotation catches this immediately.

Trying to override static methods: Static methods belong to the class, not the instance. You can define a static method with the same name in a subclass, but this is method hiding, not overriding – behaviour is very different.

Confusing the two concepts in interviews: A very common interview trap. Remember – overloading is same class, compile-time, different parameters. Overriding is parent-child, runtime, same parameters.

Frequently Asked Questions

Can we overload and override the same method?

Not the same method simultaneously – but a class can have overloaded methods, and those individual methods can each be overridden by subclasses separately.

Can constructors be overridden?

No. Constructors cannot be overridden because they are not inherited. However, constructors can be overloaded – and this is extremely common in Java.

What happens if we override a method incorrectly?

Without @Override, Java may simply treat your method as a new method in the subclass rather than an override, silently breaking your intended polymorphic behaviour. With @Override, the compiler catches the mistake immediately.

Michael Jordan gambling stories are a permanent fixture of his legendary career. While his high-stakes golf bets and casino visits are well-documented, his competitive nature is often cited as the root cause. Despite numerous rumors over the decades—including speculation about his first retirement—there has never been official evidence that his gambling impacted the integrity of NBA games or violated league rules beyond personal conduct.

Jordan himself has never fully denied the gambling – he’s acknowledged it while pushing back on characterizations of it as an addiction or crisis.

Key Documented Incidents

Incident Year What Happened
Hilton Head golf debt 1992 Jordan lost (reportedly) $57,000 to businessman James “Slim” Bouler; Bouler later convicted of drug charges; Jordan testified the check was a loan
Richard Esquinas’ book 1993 San Diego businessman wrote *Michael & Me: Our Gambling Addiction… My Cry for Help* claiming Jordan owed him $1.25 million from golf betting
First retirement (October 1993) 1993 Jordan retired suddenly at 30, 18 months before he returned; no official connection to gambling was proven
NBA investigation 1992-1993 NBA investigated Jordan’s gambling; Commissioner Stern said no violations of league rules were found
Casino in Atlantic City 1993 Jordan was photographed in a casino the night before a playoff game vs the Knicks; generated significant coverage
*The Last Dance* admission 2020 Jordan acknowledged gambling heavily; said it was competitive instinct, not addiction

The Golf Gambling Question

Golf gambling was central to most of the documented incidents. Jordan is a serious golfer with a reported handicap that has varied over the years, and high-stakes golf bets – thousands to tens of thousands per hole – have been a consistent part of his game.

Richard Esquinas’ 1993 book claimed Jordan lost $1.25 million to him over a series of golf matches and then negotiated the debt down to $300,000. Jordan’s response was to characterize the losses as much lower than claimed and to question Esquinas’ characterization of their relationship.

The dispute was never fully resolved in public.

The First Retirement: The Conspiracy Theory

Jordan’s sudden retirement in October 1993 – just months after the NBA investigation, weeks after his father’s murder – generated enormous speculation that he had been quietly pushed out by the league over gambling concerns.

The NBA has consistently denied this. David Stern said at the time there was no connection. Jordan himself has denied it.

What’s true:

  • The timing was unusual
  • Jordan’s father James Jordan was murdered in July 1993
  • Jordan had just won his third consecutive championship
  • He returned to basketball 18 months later

The conspiracy remains unproven but resurfaces reliably in basketball discussion, particularly after *The Last Dance* revisited this period.

What Jordan Has Actually Said

In *The Last Dance* documentary (2020), Jordan was notably candid:

*”I have a competitive nature. I’m not going to back down from anything that’s competitive.”*

He framed his gambling as an extension of the same competitive drive that made him the greatest player of his era – not as a problem requiring treatment or correction. He acknowledged the large bets but pushed back on characterizations of the amounts and context.

He also said: *”I don’t have a gambling problem. I have a competition problem.”* Whether that’s self-awareness or rationalization is genuinely debatable.

Impact on His Legacy

Dimension Assessment
On-court career No verified impact; six championships, six Finals MVPs
NBA investigation Cleared; no violations found
Public perception Persistent narrative that humanizes him for some; concerns others
Business reputation No apparent commercial impact; Jordan Brand exceeds $6B/year
Hall of Fame status Not affected

The gambling controversy is the most human story in Jordan’s legacy – a reminder that the greatest competitor in basketball history applied that same compulsive competitiveness to everything, including contexts where it cost him financially.

The Bottom Line

Michael Jordan’s gambling is documented, significant in scale, and genuinely interesting as a portrait of a competitive personality taken to extremes. What isn’t proven is any connection between gambling and his NBA career outcomes. Jordan won six championships, was cleared of any rule violations, and built a post-career business empire that suggests no meaningful consequences. The story endures because it complicates the perfect narrative – which is probably why it’s never fully gone away.