Basically, it is referred to as polymorphism. You can take the below code as your reference:
public class Person {
public Person() {
}
public void introduceYourself() {
}
}
public class Texan extends Person {
public Texan() {
}
public void introduceYourself() {
System.out.printLn("Howdy y'all!");
}
}
public class NewYorker extends Person {
public NewYorker() {
}
public void introduceYourself() {
System.out.printLn("Yo. You got a problem with that?");
}
}
So reference variable will help you determine which instance is called and it will provide the result accordingly.
I hope this will help.
Want to know more about Java? Prefer this tutorial on Java Tutorial.
Want to become a Java Expert? Join Java Course now!!