/**
 * Demonstrates polymorphism 
 * and that static methods are inherited but cannot be overridden.
 */
public class CarLot {

    public static void main(String[] args) {
        
        Car[] mycars = new Car[3];
        
        Car car = new Car(35);
        Hybrid hybrid = new Hybrid();
        Electric electric = new Electric();
        
        mycars[0] = car;
        mycars[1] = hybrid;
        mycars[2] = electric;
        
        // note that mycar[1] and hybrid are two variables referencing
        // the *same* object--of type Hybrid.  
        
        // This code calls an instance method, so dynamic dispatch is used.
        // Both execute the Hybrid class's method
        System.out.println(hybrid.getTankSize());
        System.out.println(mycars[1].getTankSize());
            
        // This code calls a static method.
        // The first will call Hybrid's static method, which makes sense
        // The second will call Car's static method, because mycars[1] is a
        // Car variable.  Dynamic dispatch is not used.
        System.out.println(hybrid.staticMethod());
        System.out.println(mycars[1].staticMethod());
        
        // Output:
        // Hybrid's static method
        // Car's static method
    }

}
