Which class objects can be stored into interface type arrays?
class Array19
{
public static void main(String[] args)
{
Runnable[] r=new Runnable[5];
r[0]=new Thread();
r[1]=new String("altaf");
for(Runnable a:r)
System.out.println(a);
}
}
/*
Output:- CE[incompatible types]
Explanation:- For interface type arrays, we can store only its implementation class objects.
Here String is not implementation class of Number class.
*/
{
public static void main(String[] args)
{
Runnable[] r=new Runnable[5];
r[0]=new Thread();
r[1]=new String("altaf");
for(Runnable a:r)
System.out.println(a);
}
}
/*
Output:- CE[incompatible types]
Explanation:- For interface type arrays, we can store only its implementation class objects.
Here String is not implementation class of Number class.
*/
0 comments: