Social Media

Dynamic Binding – Runtime

  • Runtime time
  • Overriden methods

The example below will compile, and the runtime environment will output “Riding fast” –

[sourcecode language=”java”] public class DynamicBinding {
public static void main(String args[]) {
Bicycle bicycle = new RaceBike();
bicycle.ride();
}
}

class Bicycle {
public void ride() {
System.out.println("Just riding my bike");
}
}

class RaceBike extends Bicycle {
@Override
public void ride() {
System.out.println("Riding fast");
}
}
[/sourcecode]

About the Author Martin Farrell

My name is Martin Farrell. I have almost 20 years Java experience. I specialize inthe Spring Framework and JEE. I’ve consulted to a range of businesses, and have provide Java and Spring mentoring and training. You can learn more at About or on my consultancy website Glendevon Software

follow me on:

Leave a Comment: