|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objecttips.casting.Main
Just holds a main for this particular set of tips.
Given the set of classes Fruit, Apple, Squeezable, Citrus and Orange, this program demonstrates what happens when you try to cast each one to every another type.
The results are shown by the use of a ClassCastException
Sample output:
Checking casts for Object
Fruit: No Citrus: No Squeezable: No Apple: No Orange: No
Checking casts for Fruit
Object: OK Citrus: No Squeezable: No Apple: No Orange: No
Checking casts for Citrus
Object: OK Fruit: OK Squeezable: OK Apple: No(*) Orange: No
Checking casts for Apple
Object: OK Fruit: OK Citrus: No(*) Squeezable: No Orange: No
Checking casts for Orange
Object: OK Fruit: OK Citrus: OK Squeezable: OK Apple: No(*)
* = Compile time error
| Constructor Summary | |
Main()
|
|
| Method Summary | |
(package private) static void |
casting()
Methd call that casts just about everything to everything else! |
(package private) static void |
conversion()
Method to check converting |
static void |
main(java.lang.String[] args)
Main function that runs through each of the classes in the sample heirarchy trying to convert from one to another |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public Main()
| Method Detail |
public static void main(java.lang.String[] args)
args - static void conversion()
static void casting()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||