tips.casting
Class Main

java.lang.Object
  extended bytips.casting.Main

public class Main
extends java.lang.Object

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

Main

public Main()
Method Detail

main

public 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

Parameters:
args -

conversion

static void conversion()
Method to check converting


casting

static void casting()
Methd call that casts just about everything to everything else!