The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
April 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Thanks

Posted by Villanueva on April 24, 2001 at 6:53 PM

Thanks, it is what I wanted.

> hi
> if you are interested in having an array of different classes and then as per the class ,the method of that class is to be called.then consider the following code
> Object o[]=new Object[2];
> o[0]=new a();//a is any class having a method show
> o[1]=new aa()//aa is any class having a method show1
> for(int i=0;i> {
> if(o[i] instanceof a)
> {
> ((a)o[i]).show();
> }
> else if(o[i] instanceof aa)
> ((aa)o[i]).show1();
> }
> do write if are not satisfied with it
> tejinder






Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us