// Poly Basics
// see also inherit0_detailed.txt

class A {}
class B extends A {}

class Vehicle{}
class Car extends Vehicle {}

public class poly_basics {
    public static void main(String[] args) {
	
	// B is a B:
	B b1 = new B();
	Car c1 = new Car();
	int x1 = 7;
	
	// B is an A: 
	// Say as, "a B-object may have an A-type"
	// So, A Car-object can be type Car or Vehicle:
	A b2 = new B();
	Vehicle c2 = new Car();
	double x2 = 7;
	
	// Redundant version of "B is an A":
	A b3 = (A) new B();
	Vehicle c3 = (Vehicle) new Car();
	double x3 = (double) 7;
	
	// Is A a B? Can you go backwards? Kind of...
	// (Is a Vehicle a Car? Only sometimes!)
	// Use a cast to access only the "sometimes" 
	// portion of an object:
	// B b4 = (B) new A();
	// Car c4 = (Car) new Vehicle();
	// int x4 = (int) 7.7;
	// Java does have a problem dealing with 
	// reverse is-a relationships.	
    }
}