class Array_2
{
public static void main(String[] args)
{
int[] a={10,20,30,40,50};
for(int i=0; i<a.length;i++)
{
System.out.println(a[i]);
}
Emp[] e=new Emp[5];
Emp e1= new Emp(111,"ashutosh");
Emp e2= new Emp(222,"kumar");
Emp e3= new Emp(333,"singh");
Emp e4= new Emp(444,"lagatar haso");
Emp e5= new Emp(444,"naya ghar");
Emp e6= new Emp(444,"purana");
Emp e7= new Emp(444,"aaj");
e[0]=e1;
//e[1]=e2;
e[2]=e3;
//e[3]=e4;
e[4]=e5;
//e[5]=e6; RTE ArrayIndexOutOfBoundsException
for(Object O:e)
{
if(O instanceof Emp)
{ Emp ee= (Emp)O; //DOWN CASTING HAS TO BE DOWN EXPLICITLY
System.out.println(ee.id+"-----"+ee.name);
}
if(O==null)
{ System.out.println(O);
}
}
for(int i=0;i<e.length;i++)
{
if(e[i]==null)
{System.out.println(i);}
}
Array_1 a1=new Array_1();
a1.m1();
}
}
Thanks
Happy programming!
{
public static void main(String[] args)
{
int[] a={10,20,30,40,50};
for(int i=0; i<a.length;i++)
{
System.out.println(a[i]);
}
Emp[] e=new Emp[5];
Emp e1= new Emp(111,"ashutosh");
Emp e2= new Emp(222,"kumar");
Emp e3= new Emp(333,"singh");
Emp e4= new Emp(444,"lagatar haso");
Emp e5= new Emp(444,"naya ghar");
Emp e6= new Emp(444,"purana");
Emp e7= new Emp(444,"aaj");
e[0]=e1;
//e[1]=e2;
e[2]=e3;
//e[3]=e4;
e[4]=e5;
//e[5]=e6; RTE ArrayIndexOutOfBoundsException
for(Object O:e)
{
if(O instanceof Emp)
{ Emp ee= (Emp)O; //DOWN CASTING HAS TO BE DOWN EXPLICITLY
System.out.println(ee.id+"-----"+ee.name);
}
if(O==null)
{ System.out.println(O);
}
}
for(int i=0;i<e.length;i++)
{
if(e[i]==null)
{System.out.println(i);}
}
Array_1 a1=new Array_1();
a1.m1();
}
}
Thanks
Happy programming!
No comments:
Post a Comment