type conversion in Java

Type casting is when you assign a value of one primitive data type to another type.
In Java, there are two types of casting:
* Widening Casting (automatically) - converting a smaller type to a larger type size
    byte -> short -> char -> int -> long -> float -> double
* Narrowing Casting (manually) - converting a larger type to a smaller size type
    double -> float -> long -> int -> char -> short -> byte 

Here are some basic rules when casting reference variables:
* Casting an object from a subclass to a superclass doesn’t require an explicit cast.
* Casting an object from a superclass to a subclass requires an explicit cast.
* The compiler will not allow casts to unrelated types.
* Even when the code compiles without issue, an ClassCastException may be thrown at runtime if the object being cast is not actually an instance of that class.

you can use the instanceof operator prior to casting the object to avoid throwing ClassCastException at runtime:
```
if(rodent instanceof Capybara) {
   Capybara capybara = (Capybara)rodent;
}
```