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:
use of object array
Posted by tejinder singh on April 24, 2001 at 1:51 PM
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:
- Thanks Villanueva April 24, 2001 at 6:53 PM
(0)
|