SDSU CS 596 Client-Server Programming
Misc.

[To Lecture Notes Index]
San Diego State University -- This page last updated February 6, 1996
----------

Casting and Classes
class  Parent  {  int  data;  }

class  Child  extends  Parent  {  String  name;  }

class  Uncle  {  String  rich;  }

class  Casting
	{
	public static void main( String args[] ) 
		{
		Object  object;
		Parent  parent;
		Child  child  =  new Child();
		Uncle  uncle;

		parent  =  child;
		object  =  child;
		parent  =  (Parent)  object;
		child  =  (Child)  object;

		uncle  =  (Uncle)  object;	//Runtime exception
		}
}
Output
java.lang.ClassCastException: Child
at Casting.main(All.java:21)

NaN and Infinity

class Compare  
	{

	public static void main( String args[] ) 
		{
		float  nan  =  Float.NaN;
		float  positiveInfinity  =  Float.POSITIVE_INFINITY;
		float  negativeInfinity  =  Float.NEGATIVE_INFINITY;

		// False Statements
		System.out.println(  nan == nan  );
		System.out.println(  nan < nan  );
		System.out.println(  nan > nan  );
		System.out.println(  positiveInfinity  <  positiveInfinity  );


		// True Statements
		System.out.println(  positiveInfinity  == positiveInfinity  );
		System.out.println(  5.2 < positiveInfinity  );
		System.out.println(  5.2 > negativeInfinity  );

		}
	}

----------