Top Topics in our Forum';
**Interactive equation of a circle. Click and drag to see equation in action!

A+    A−    B  
Algebra
Games
Geometry
Interactive
Trigonometry
Forum




AddThis Social Bookmark Button

Java Casting

How to and When to Cast Objects

"Read R to L"
ie Is "what is on the right" always "what is on the left" ?
Example 1) 
String str ="word";
Comparable p = str;//OK String is a Comparable 
"a String(str) is a Comparable"
Remember Strings implements the Comparable interface

Bad String str="words" Comparable p ="str; String t = p; //BAD becuase NOT all Comparables are Strings

Ok if you (cast) String str="words" Comparable p ="str; String t = (String)p ; // OK becuase NOT all Comparables are Strings
C1 implements i1 and i2 C c1 = i1 ;;yes

Top
AddThis Social Bookmark Button