• Skip to main content

CPlatt Portfolio

Creating a Visually Stunning Web

  • Portfolio
  • Blog

Design

Java Polymorphism: Overloading, Overriding, Interfaces, and Dynamic Dispatch (Explained)

April 11, 2026 by Chris Platt

Introduction

You’ve probably seen this moment in Java:

You call a method on a variable that looks like one type, but at runtime it behaves like a different one. Maybe you expected one output… and got another.

Or you wrote two methods with the same name (overloading), then later added a subclass and overrode one of them—only to realize Java chose a different method than you thought.

These bugs aren’t random. They’re the result of how Java handles polymorphism, specifically overloading, overriding, interfaces, and dynamic dispatch. Let’s make these concepts feel predictable instead of mysterious.

Main Concepts

Polymorphism in plain English

Polymorphism means: the same method call can result in different behavior depending on the situation.

In Java, that “situation” is usually either:

  • Compile-time type (what the variable is declared as)
  • Runtime type (what object you actually have)

Java uses both in different ways depending on whether you’re dealing with overloading or overriding.


Overloading: compile-time choice

Overloading happens when multiple methods have the same name in the same class (or subclass) but different parameter lists.

Java decides which overloaded method to call based on the compile-time types of the arguments.

That means overloading is mostly determined before the program runs.

Example:

class Calculator {
    int add(int a, int b) {
        return a + b;
    }

    double add(double a, double b) {
        return a + b;
    }
}

If you call add(1, 2) you’ll get the int version, because both arguments are compile-time int.

But if you do:

Calculator c = new Calculator();
System.out.println(c.add(1, 2.0));

Java will select the best match based on the compile-time argument types (here: int + double triggers numeric conversions and selects the double overload).

Key point: overloading does not depend on runtime object type. It depends on the method call signature Java sees at compile time.


Overriding: runtime choice

Overriding happens when a subclass provides a new implementation of a method declared in a superclass.

Unlike overloading, overriding is resolved using the runtime type of the object.

That’s where polymorphism really kicks in.

Example:

class Animal {
    void speak() {
        System.out.println("Animal sound");
    }
}

class Dog extends Animal {
    @Override
    void speak() {
        System.out.println("Woof");
    }
}

Now compare:

Animal a = new Dog();   // compile-time: Animal, runtime: Dog
a.speak();              // prints "Woof"

Even though the variable a is declared as Animal, the JVM calls Dog.speak() because the actual object is a Dog.

Key point: overriding is dynamic dispatch.


Dynamic dispatch: the mechanism

Dynamic dispatch is the runtime process that selects the correct overridden method implementation.

When you call a.speak(), Java doesn’t just “look up” speak() in the Animal class and stop there. Instead, it checks the actual runtime class of a and invokes the method that matches that class’s override.

This is what makes polymorphism useful: you can write code against a general type (Animal) and still get specific behavior (Dog, Cat, etc.).


Interfaces: polymorphism without inheritance

You can achieve polymorphism using interfaces too—often preferred in real code because it avoids deep inheritance trees.

An interface defines a contract:

interface Payment {
    void pay(int amount);
}

Different classes implement it:

class CardPayment implements Payment {
    @Override
    public void pay(int amount) {
        System.out.println("Paid " + amount + " using a card");
    }
}

class CashPayment implements Payment {
    @Override
    public void pay(int amount) {
        System.out.println("Paid " + amount + " using cash");
    }
}

Now write code against the interface:

void checkout(Payment payment) {
    payment.pay(50);
}

Call it like this:

checkout(new CardPayment()); // Paid 50 using a card
checkout(new CashPayment()); // Paid 50 using cash

Same method call (pay(50)), different behavior at runtime. That’s polymorphism via interfaces + dynamic dispatch.


Putting it together: compile-time vs runtime

A good mental model:

  • Overloading: decided at compile time using argument types.
  • Overriding: decided at runtime using the object’s actual type.

Mix those up and you’ll get surprising results.

Example

Let’s build a small scenario that includes overloading, overriding, and interfaces in one place.

Step 1: Define an interface with an overriding target

interface Shape {
    int area();                 // overridden implementations
    String describe();         // overridden implementations
}

Step 2: Create two implementations

class Rectangle implements Shape {
    private final int w;
    private final int h;

    Rectangle(int w, int h) {
        this.w = w;
        this.h = h;
    }

    @Override
    public int area() {
        return w * h;
    }

    @Override
    public String describe() {
        return "Rectangle";
    }
}

class Square extends Rectangle {
    private final int side;

    Square(int side) {
        super(side, side);
        this.side = side;
    }

    @Override
    public int area() {
        return side * side;
    }

    @Override
    public String describe() {
        return "Square";
    }
}

Step 3: Add overloading in a separate utility method

class Printer {
    // Overloaded: compile-time selection
    void print(Shape s) {
        System.out.println("Shape: " + s.describe() + ", area=" + s.area());
    }

    void print(Rectangle r) {
        System.out.println("Rectangle-ish: " + r.describe() + ", area=" + r.area());
    }
}

Step 4: Observe what happens when you call overloaded methods

public class Demo {
    public static void main(String[] args) {
        Printer printer = new Printer();

        Shape shape = new Square(4);     // compile-time Shape, runtime Square
        Rectangle rect = new Square(4);  // compile-time Rectangle, runtime Square

        printer.print(shape);
        printer.print(rect);
    }
}

What to expect:

  • printer.print(shape):

    • Overload choice uses compile-time type: Shape
    • It calls print(Shape s)
    • Inside, s.describe() and s.area() use dynamic dispatch:
    • shape is actually a Square, so you get "Square" and 16
  • printer.print(rect):

    • Overload choice uses compile-time type: Rectangle
    • It calls print(Rectangle r)
    • Again, overridden methods (describe, area) are selected at runtime from Square

This example highlights the “two-stage” behavior: overloading picks the method, then overriding chooses the behavior inside.

Practical Use

1) Write flexible code with interfaces

When you define something like Payment, Notification, or Storage, you can build the rest of your system around that interface. That keeps your code open for extension:

  • Add PayPalPayment later without rewriting the checkout flow.

2) Use @Override aggressively

Junior devs often forget @Override, and then accidentally create a new method instead of overriding (wrong signature, different parameters, etc.). With @Override, the compiler helps you catch the mistake early.

@Override
public int area() { ... }

3) Prefer overriding for behavior, overloading for convenience

Overloading is great for APIs that accept different input types, like:

  • read(String path)
  • read(Path path)
  • read(File file)

Overriding is for polymorphic behavior—like different shapes, animals, renderers, strategies, etc.

4) Expect dynamic dispatch in polymorphic code

If you have:

List<Shape> shapes = List.of(new Square(2), new Rectangle(2, 3));
for (Shape s : shapes) {
    System.out.println(s.describe() + ": " + s.area());
}

You should expect each element to call its own overridden implementation.

Common Mistakes

Mistake 1: Assuming overloading uses runtime types

Consider:

class A {}
class B extends A {}

class Test {
    void m(A a) { System.out.println("A"); }
    void m(B b) { System.out.println("B"); }
}

If you do:

Test t = new Test();
A x = new B();
t.m(x);

You might want "B", but Java prints "A" because overload selection uses compile-time type (A), not runtime type (B).

Mistake 2: Confusing “is-a” with “has-a”

Polymorphism feels like inheritance, but interfaces help you express capability:

  • Square implements Shape (capability)
  • not Square is-a Rectangle as the only design tool

Inheritance is not always the right first choice.

Mistake 3: Forgetting that fields don’t use dynamic dispatch

This one surprises people. If you override a field (you can’t truly override fields in Java like methods; you can hide them), polymorphism doesn’t behave the same way.

Methods dispatch dynamically; fields are selected differently. If you need polymorphic state, store it in methods or use separate objects.

Mistake 4: Overriding without matching the signature

If you write:

class Cat extends Animal {
    void speak(int volume) { ... } // different signature
}

You didn’t override speak(). You added a new method. Calls to speak() still use Animal.speak() unless the signature matches.

Conclusion

Java polymorphism is powerful, but it has two distinct “selection rules”:

  • Overloading is chosen at compile time based on the declared argument types.
  • Overriding uses dynamic dispatch at runtime based on the actual object type.
  • Interfaces make polymorphism flexible and composable, often reducing reliance on deep inheritance.
  • Dynamic dispatch is what makes Animal a = new Dog(); a.speak(); print “Woof”.

Practical takeaways

  • Use overriding for behavior differences between subclasses/implementations.
  • Use overloading for convenience when multiple input shapes can map to the same concept.
  • Program to an interface when you want extensibility.
  • Always annotate overrides with @Override.
  • When something “feels wrong,” ask: Did Java choose the method based on compile-time or runtime types?

Once you internalize that split, polymorphism stops being a source of surprises—and becomes a tool you can rely on.

Filed Under: Design, Development, Programming

The Latest Design Trends in Web Design: Minimalism, Flat Design, and Dark Mode

March 28, 2023 by Chris Platt

Web design trends are constantly evolving, and it can be challenging to keep up with the latest styles and techniques. In this blog post, we’ll explore some of the latest design trends in web design, including minimalism, flat design, and dark mode. We’ll also share some examples of websites that are using these trends effectively.

Minimalism

Minimalism has been a popular trend in web design for several years now, and it shows no signs of slowing down. Minimalist websites are characterized by clean lines, ample white space, and a focus on typography. This trend emphasizes simplicity and clarity, and it’s an excellent choice for businesses that want to convey a sense of professionalism and sophistication.

One excellent example of a minimalist website is Dropbox. The Dropbox homepage features a simple layout with a bold heading and a call to action button. The website’s white background and clean typography create a sense of elegance and professionalism, while the use of subtle animations adds a touch of playfulness.

Flat Design

Flat design is another popular trend in web design that emphasizes simplicity and minimalism. Flat design is characterized by a lack of shadows, gradients, and other 3D effects. Instead, flat design relies on clean lines, bright colors, and simple shapes to create a modern and sleek look.

An excellent example of a website that uses flat design effectively is Stripe. The Stripe homepage features a clean and simple layout with bold headings, simple icons, and bright colors. The use of flat design creates a sense of modernity and innovation, which is perfect for a company that provides online payment services.

Dark Mode

Dark mode is a relatively new trend in web design that has been growing in popularity in recent years. Dark mode is characterized by a black or dark background with light-colored text and graphics. This trend is ideal for websites that want to create a sense of drama and elegance, and it’s an excellent choice for websites that cater to creative or tech-savvy audiences.

One excellent example of a website that uses dark mode effectively is Apple’s website. Apple’s website features a dark background with light-colored text and graphics, which creates a sense of drama and sophistication. The use of dark mode is particularly effective for showcasing Apple’s products, which are known for their sleek and modern design.

Minimalism, flat design, and dark mode are just a few of the latest trends in web design. Each of these trends emphasizes simplicity, clarity, and modernity, making them an excellent choice for businesses that want to create a sense of professionalism and sophistication. By incorporating these trends into your website design, you can create a modern and sleek look that will impress your visitors and help your business stand out online.

Filed Under: Design, Web

The Importance of Responsive Design: Why Your Website Needs to Look Great on All Devices

March 27, 2023 by Chris Platt


In today’s digital age, more and more people are accessing the internet on mobile devices like smartphones and tablets. In fact, mobile devices now account for more than half of all internet traffic worldwide. With this in mind, it’s essential to have a website that looks great and functions well on all screen sizes. This is where responsive design comes in.

What is Responsive Design?

Responsive design is a web design approach that allows a website to adapt to different screen sizes and devices. With responsive design, a website’s layout and content will adjust to fit the screen size of the device being used, whether it’s a desktop computer, a tablet, or a smartphone. This ensures that the website is easy to navigate and read, regardless of the device being used.

Benefits of Responsive Design

There are many benefits to using responsive design for your website. Here are just a few:

  1. Improved User Experience

Responsive design ensures that your website is easy to use and navigate on all devices, which leads to a better user experience. Visitors to your website will appreciate being able to access your content easily, no matter what device they are using.

  1. Increased Mobile Traffic

With more and more people accessing the internet on mobile devices, having a website that looks great on smartphones and tablets is essential. Responsive design ensures that your website is accessible to all visitors, regardless of the device they are using. This can help to increase mobile traffic to your site and boost engagement.

  1. Better Search Engine Rankings

Search engines like Google prioritize mobile-friendly websites in their search results. By using responsive design, you can improve your website’s mobile-friendliness and boost your search engine rankings.

Tips for Implementing Responsive Design

Implementing responsive design for your website may seem daunting, but there are a few tips that can make the process easier:

  1. Use a Responsive Design Framework

There are many responsive design frameworks available, such as Bootstrap and Foundation, that can help you create a responsive website quickly and easily. These frameworks provide pre-built templates and CSS styles that you can use to create a website that looks great on all devices.

  1. Optimize Images for Mobile

Large images can slow down your website’s load time on mobile devices. Make sure to optimize images for mobile devices by using compressed file formats and smaller image sizes.

  1. Test Your Website on Multiple Devices

It’s important to test your website on multiple devices to ensure that it looks and functions as intended. This can help you identify any issues with your website’s layout or functionality on specific devices.

Responsive design is essential for any website that wants to provide a great user experience across all devices. By implementing responsive design and optimizing your website for mobile, you can improve engagement, increase traffic, and boost your search engine rankings.

Filed Under: Design, Development, Web

What are the Right Questions?

February 13, 2023 by Chris Platt

Asking the right questions during a web design consultation is crucial to ensure the success of your website build. A consultation allows you to discuss your project with a web designer, clarify your goals and objectives, and determine the best course of action. In this blog post, we’ll explore some of the key questions you should ask during a web design consultation to help you get the most out of your website build.

What is the process for creating a website?

It’s important to understand the steps involved in building a website. Ask the web designer to outline their process from start to finish, including how they handle revisions, communication, and testing.

How do you approach website design?

This question will help you get a sense of the web designer’s design philosophy and approach. Are they focused on functionality, or do they prioritize aesthetics? Do they prefer to use a certain type of design style, such as minimalism or flat design? Understanding the designer’s approach can help you ensure that your website will reflect your desired aesthetic.

Can you provide examples of websites you have designed in the past?

Asking for examples of previous work can give you a good idea of the designer’s experience and capabilities. It’s also a good opportunity to see how they’ve handled similar projects and to evaluate their design style.

What is your process for website optimization?

Website optimization is crucial for search engine ranking and user experience. Ask the designer how they approach optimization, including how they plan to improve load times and make the website mobile-friendly.

How do you handle revisions and changes?

Changes are inevitable during a website build, and it’s important to understand how the designer handles revisions. Ask about their revision process, how many revisions are included in the project scope, and how they handle changes beyond the original scope of the project.

What is your project timeline and budget?

It’s important to have a clear understanding of the timeline and budget for your project. Ask the designer for an estimated timeline, including how long it will take for the website to be completed, and for a breakdown of the costs involved in the project.

What support do you offer after the website is launched?

The website build is just the beginning. Ask the designer what support they offer after the website is launched, including website maintenance, security updates, and ongoing technical support.

Asking the right questions during a web design consultation is essential to ensure a successful website build. By understanding the designer’s process, approach, and capabilities, you can ensure that your website will meet your goals and objectives. Additionally, by discussing budget, timeline, and post-launch support, you can ensure that your project is completed on time, within budget, and with the support you need to maintain your website long-term.

Filed Under: Branding, Design, Web

What is Web Design?

February 6, 2023 by Chris Platt

Web Design refers to the creation of digital environments that facilitate and encourage human activity through the use of markup languages, styling, and interactivity. It encompasses various disciplines, including graphic design, user experience design, interface design, and others, to produce aesthetically pleasing and user-friendly websites.

A web designer is responsible for the visual and interactive elements of a website, including the layout, typography, color palette, and overall appearance. Their goal is to create a website that effectively communicates the brand’s message and provides an excellent user experience.

Good web design should be visually appealing, but it is also crucial to create a website that is easy to navigate and use. This includes having a clear and logical structure, intuitive navigation, and well-organized content. A user-centered approach to design should always be taken, meaning that the website should be designed with the user in mind, rather than just being pleasing to the eye.

Web design also involves technical considerations, such as the use of responsive design to ensure the website is optimized for different screen sizes, as well as accessibility considerations for users with disabilities. It also involves ensuring that the website is optimized for search engines, making it easier for users to find the website through search results.

Web design is a crucial aspect of modern business and digital communication. A well-designed website can enhance the brand image, increase user engagement, and drive conversions. Whether it’s a simple brochure website or a complex e-commerce platform, effective web design is essential for the success of any online presence.

Filed Under: Design, Development, Web

The Power of a Solid Branding System

January 30, 2023 by Chris Platt

Branding is a crucial aspect of any business, big or small. A strong brand can differentiate your business from competitors, establish trust with your target audience, and ultimately drive sales. A good branding system not only creates a consistent look and feel for your company, but also helps you convey your values and what sets you apart from others.

Having a consistent brand image and messaging across all channels (website, social media, packaging, advertising, etc.) can greatly improve your brand recognition and make a lasting impression on customers. A well-designed branding system ensures that your business appears professional, trustworthy, and relevant in the eyes of your target audience.

Additionally, a good branding system provides a framework for all future marketing and communication efforts. It helps guide your decision-making process and ensures that every touchpoint with your customers aligns with your overall brand strategy. This level of consistency makes it easier for customers to recognize and remember your brand, and reinforces your company’s position in their minds.

Moreover, a good branding system can increase customer loyalty. By consistently delivering on your brand promise and values, you build trust with your target audience. This trust can lead to repeat business, positive word-of-mouth, and even brand advocacy.

In conclusion, a good branding system is essential for any business looking to establish a strong and recognizable brand presence. A well-designed branding system provides a consistent look and feel, reinforces your brand strategy, and helps you build trust and loyalty with your target audience. Investing in a good branding system is an investment in the future success of your business.

Filed Under: Branding, Design, Web

White Space Isn’t Just An Empty Gesture

January 16, 2023 by Chris Platt

White space, also known as negative space, is an often-undervalued aspect of design. In this post, we will delve into the importance of white space in design and why it should not be overlooked.

Clarity and Readability

White space is crucial in providing a clear visual hierarchy in a design. It helps to separate elements, making them easier to understand and read. With the right use of white space, a designer can create a clean and organized layout that is easy on the eyes.

Focuses Attention

White space can be used to direct the viewer’s attention to a particular element in a design. By surrounding the main focus of the design with white space, a designer can emphasize the importance of that element, making it stand out.

Creates Balance

White space can be used to create balance and proportion in a design. By using the right amount of white space, a designer can create a harmonious and visually pleasing layout. An unbalanced design can look cluttered and confusing, but with the use of white space, the elements can be arranged in a way that is aesthetically pleasing.

Conveys Professionalism

Designs that utilize white space effectively often look polished and professional. A well-designed layout with ample white space gives the impression that the designer has put thought and effort into the design, making it more appealing and trustworthy.

White space should not be considered as just “empty” space in a design. Instead, it should be used to enhance the overall look and feel of a design. Whether it’s used to create clarity, focus attention, balance, or convey professionalism, white space is an essential tool in a designer’s arsenal.

Filed Under: Design, Web

The Future of Web Development: Trends and Predictions for 2023 and Beyond

January 9, 2023 by Chris Platt

Web development has come a long way since the early days of the World Wide Web. The field has evolved at a rapid pace and is expected to continue doing so in the future. In this blog post, we’ll take a look at some of the key trends and predictions for the future of web development.

Progressive Web Apps (PWAs)

Progressive Web Apps (PWAs) are a new way of building web applications that provide a native app-like experience to users. PWAs are fast, reliable, and can be installed on the home screen of a user’s device without the need for downloading an app from an app store. This makes PWAs a powerful tool for businesses looking to engage with their customers in a more meaningful way. In the coming years, we can expect to see an increase in the adoption of PWAs as more businesses realize the benefits of this technology.

Artificial Intelligence and Machine Learning

Artificial Intelligence (AI) and Machine Learning (ML) are set to play a huge role in the future of web development. These technologies will allow developers to create more intelligent and dynamic web applications that can adapt to the needs of their users. AI and ML will also enable the creation of personalized experiences, with applications that can tailor their behavior to the individual user.

5G Technology

The advent of 5G technology is set to revolutionize the web development landscape. With its high speeds and low latency, 5G will enable the creation of more immersive and interactive web experiences. This will be particularly important for virtual and augmented reality applications, which will become more accessible to a wider audience with the advent of 5G.

Focus on User Experience (UX)

User experience (UX) will continue to be a key focus for web developers in the future. As the web becomes increasingly complex, web developers will need to ensure that their applications are intuitive and easy to use. This will involve paying close attention to the design and functionality of web applications, as well as ensuring that they are accessible to users with disabilities.

Cross-Platform Development

Cross-platform development will become increasingly important in the future, as web developers look to reach users on a variety of devices and platforms. This will require web developers to adopt new tools and technologies that allow them to build web applications that work seamlessly across different devices and operating systems.

The future of web development looks bright, with new technologies and trends set to revolutionize the way that web applications are built and used. Whether it’s the rise of PWAs, the impact of AI and ML, the advent of 5G technology, a focus on UX, or the importance of cross-platform development, the future of web development promises to be an exciting and challenging time for developers and businesses alike.

Filed Under: Design, Development, Web

CPlattDesign © 2012–2026