Java
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   padmavathi_kesavamatham
Posted On:   Thursday, February 9, 2006 09:57 AM

import java.util.*; class base { //some methods. } class a extends base { public void aMethod() { System.out.println("In aMethod"); } } class b extends base { public void bMethod() { System.out.println("In bMethod"); } } class c extends base { public void cMethod() { System.out.println("In cMethod"); } } class InMain { public static void main(String[] args) { System.out.println("Hello World!");    More>>

import java.util.*;


class base
{
//some methods.
}


class a extends base
{


public void aMethod()
{
System.out.println("In aMethod");
}
}


class b extends base
{


public void bMethod()
{
System.out.println("In bMethod");
}
}


class c extends base
{


public void cMethod()
{
System.out.println("In cMethod");

}
}


class InMain
{


public static void main(String[] args)
{
System.out.println("Hello World!");
a a1=new a();
b b1=new b();
c c1=new c();
List l = new ArrayList(10);
l.add(a1);
l.add(b1);
l.add(c1);
//Now I want all the objects to be added only to a collection object and using iterator I want to dispay the objects on the console usinb System.out.println.
How to add to collection.
Is it Collection c =new ....(But collection is Interface?)


Output:
a1
b1
c1



// Iterator iter = l.iterator();
// while (iter.hasNext())
// {
// System.out.println(iter.next());
// a a2=(a)(iter.next());
// System.out.println(a2);
// b b2=(b)(iter.next());
// System.out.println(b2);
// c c2=(c)(iter.next());
// System.out.println(c2);


Enumerator enum1=l.iterator();
while(enum1.hasMoreTokens())
{
System.out.println( enum1.nextToken());
}

}
}


Help me out by sending me the correct answer.
Thanks.

   <<Less

Re: Java

Posted By:   WarnerJan_Veldhuis  
Posted On:   Thursday, February 9, 2006 11:19 AM

You could write Collection l = new ArrayList(); But since List is a sub-interface from Collection, you kind of already did that...
About | Sitemap | Contact