I have two classes(Vector and Stack) the one extends another.Resourse class has four methods.
When I pass a object of sub-class with reference of super-class it calls method that accepts super-class object not sub-class?Why does it happen?
class Vector{
}
class Stack extends Vector{
}
public class Resources {
public static void getIntS(Vector vector){
System.out.println("Int of Vector");
}
public static void getIntS(Stack stack){
System.out.println("Int of Stack");
}
public void getInt(Vector vector){
System.out.println("Int of Vector(Not static)");
}
public void getInt(Stack stack){
System.out.println("Int of Stack(Not static)");
}
public static void main(String[] args){
Resources resources = new Resources();
Vector vector = new Stack();
Stack stack = new Stack();
getIntS(vector);
getIntS(stack);
resources.getInt(vector);
resources.getInt(stack);
}
}
Output :
Int of Vector
Int of Stack
Int of Vector(Not static)
Int of Stack(Not static)