and are class types and is subclass of and are interface types and is subinterface of is an interface implemented by class in generala narrowing conversion of reference types requires an explicit cast alsothe correctness of narrowing conversion may not be verifiable by the compiler thusits validity should be tested by the java run-time environment during program execution the example code fragment below shows how to use cast to perform narrowing conversion from type number to type integer number new integer( )/widening conversion from integer to number integer (integernfrom number to integer /narrowing conversion in the first statementa new object of class integer is created and assigned to variable of type number thusa widening conversion occurs in this assignment and no cast is required in the second statementwe assign to variable of type integer using cast this assignment is possible because refers to an object of type integer howeversince variable is of type numbera narrowing conversion occurs and the cast is necessary casting exceptions in javawe can cast an object reference of type into type sprovided the object is referring to is actually of type ifon the other handobject is not also of type sthen attempting to cast to type will throw an exception called classcastexception we illustrate this rule in the following code fragmentnumber ninteger in new integer( ) (integern/this is legal new double( ) (integern/this is illegal