Basic HTML version of Foils prepared 17 Nov 97

Foil 17 Determining and Testing Class of Object

From Java Tutorial, July 1, 1996 CEWES Tutorial, CPS606, JSU Class CSC499 -- July 22-25 1997, Fall 97. by Nancy J. McCracken,Geoffrey C. Fox, Tom Scavo


Suppose we have an object called obj. We get the class of obj by:
Class class = obj.getClass();
and its name by:
String name = class.getName();
One can also use instanceof in following fashion:
"foo" instanceof String
evaluates to true, but
( new mPoint(x,y) ) instanceof String
evaluates to false.



© Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Wed Apr 1 1998