> ((Cat)cats.elementAt(j)).print();

as cats is a Vector and elementAt(int index) return an Object the Object
needs to be cast to a Cat so the method print() can be used, same as

Cat c = (Cat)elementAt(j);
c.print();

cheers pb...


Sampat Palani wrote:
>
> this is a simple java query
> someone asked me this
> now i dont have an explanation the example is frm bruce eckel's thinking in
> java
> //****************************************
>  import Tools.essential.*;
>  class Cat{
>         private int Catno;
>         Cat(int i){
>                 Catno = i;
>         }
>         void print(){
>                 System.out.println("Cat  " + Catno);
>         }
> }
>
> class Dog{
>         private int Dogno;
>         Dog(int i){
>                 Dogno = i;
>                 }
>         void print(){
>                 System.out.println("Dog  " + Dogno);
>         }
> }
>
> public class CatsAndDogs{
>         public static void main(String args[]){
>                 Vector cats = new Vector();
>                 for(int i=0;i<7;i++){
>                         cats.addElement(new Cat(i));
>                 }
>                 cats.addElement(new Dog(7));
>                 for(int j=0;j<cats.size();j++){
>                         ((Cat)cats.elementAt(j)).print();
>                 }
>         }
> }
> //**************************************************************************
> can anyone explanin the following line in the code
>
> ((Cat)cats.elementAt(j)).print();
>
> thanx
> regards
> Sam
>
> ===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
>  http://java.sun.com/products/jsp/faq.html
>  http://www.esperanto.org.nz/jsp/jspfaq.html
>  http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
>  http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
> .

--


--------------------------------------------------------------------------------------
Peter Blakeley
JSP Servlets JINI RMI EJB Javaspaces
[ coolcat.com.au ]

If one innocent person is executed should not all those who voted
for and or support state sanctioned killing also be executed ?
.

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to