Home arrow static arrow Java Programming [Archive] - Knowing the Object type? Is this possible?
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Knowing the Object type? Is this possible?
This topic has 3 replies on 1 page.

Posts:754
Registered: 6/13/03
Knowing the Object type? Is this possible?  
Aug 10, 2004 6:23 AM



 
Can we know the type of the object created ? Is there any method
that lets you know the type of object?

For example:

class Superclass{} class Subclass extends Superclass{ } class TestInheritance{public static void main(String[] args){ Subclass subClass = new Subclass(); }  } 


Now,Subclass is of type Subclass and also of type Superclass.
Right?

IS there any way or method I can find out the type of Subclass? ie
Subclass is of type 'Subclass' and 'Superclass'.
 

Posts:4,906
Registered: 23/07/02
Re: Knowing the Object type? Is this possible?  
Aug 10, 2004 6:45 AM (reply 1 of 3)



 
[url http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html#getClass()]Object.getClass()[/url].
 

Posts:2,067
Registered: 5/3/01
Re: Knowing the Object type? Is this possible?  
Aug 10, 2004 6:45 AM (reply 2 of 3)



 
These might help:

instanceof operator.

also

Object.getClass().className()
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Class.html
 

Posts:2,067
Registered: 5/3/01
Re: Knowing the Object type? Is this possible?  
Aug 10, 2004 6:47 AM (reply 3 of 3)



 
...and

Class.isInstance()
 
This topic has 3 replies on 1 page.