Type Casting in Java – Implicit and Explicit Casting

Type Casting in Java is  nothing but converting a primitive or interface or class in Java into other type. There is a rule in Java Language that classes or interface which shares the same type hierrachy only can be typecasted. If there is no relationship between then Java will throw ClassCastException. Type casting are of two types they are

  1. Implicit Casting (Widening)
  2. Explicit Casting (Narrowing)

[Read more…]