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


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

in Table To:


© 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