Interfaces and Method call- Handling by the JVM

So i was wondering how Something was handled by the jvm so i’ll show you with an example.
So imagine :

Person is an interface

and

Student implements Person

and that somewhere i have

public static final boolean areFriends(Person person1, Person person2){
//Do a lot of stuff to see if they're friends
}
public static final boolean areFriends(Student student1, Student student2){
//Do a single fast check to see if they're friends so using this method is better if the Person is a Student
}

So first : Is is a bad practice ?(Almost sure that’s a bad practice) And how does the jvm handle that and know which method to call ?

From my tests :


Person p1 = new Student();
Person p2 = new Student();
areFriends(p1, p2);

This calls the interface method :areFriends(Person person1, Person person2).


Student p1 = new Student();
Student p2 = new Student();
areFriends(p1, p2);

This calls the Student method : areFriends(Student student1, Student student2).

So my simple guess is that the jvm does handle this by simply using the method for the type of the object stored. But i’d like some more explanations. And a correct way to handle that, a check for instanceof feel like the code is bad designed but i don’t really see any other way.