You need to sign in to do that
Don't have an account?
om sai 10
How to access inner class variable in the loop
Hi All,
I have outer and inner class and I am trying to execute below given code from anonymous block but i am not able to access the value of the variable in the for loop,Can someody please help and let m know how to specifically access the value of variable i which is in the inner class.
public class Fridge
{
public String modelNumber='g-20';
public Integer numberInStock;
public list<RareFridge>g;
public list<Fridge.RareFridge>ftr;
public fridge(integer numberInStock)
{
modelNumber='g-20';
ftr=new list<fridge.RareFridge>();
this.numberInStock=numberInStock;
}
public list<Fridge.RareFridge> updateStock(Integer justSold)
{
numberInStock = numberInStock - justSold;
System.debug('The number in stock r es'+numberInStock);
ftr.add(new Rarefridge(20,'Gret'));
return ftr;
}
public class RareFridge
{
//publi items {get;set;}
Integer i;
String str;
public RareFridge(integer g,String str)
{
This.i=g;
this.str=str;
}
}
}
running from annonymous block
for(integer h=0;h<10;h++)
{
Fridge f=new Fridge(200);
}
public List<fridge.rarefridge>t;
t=f.updateStock(50);
for(fridge.Rarefridge m:t)
{
//System.debug('The vlue of is'+m.i);
}
I have outer and inner class and I am trying to execute below given code from anonymous block but i am not able to access the value of the variable in the for loop,Can someody please help and let m know how to specifically access the value of variable i which is in the inner class.
public class Fridge
{
public String modelNumber='g-20';
public Integer numberInStock;
public list<RareFridge>g;
public list<Fridge.RareFridge>ftr;
public fridge(integer numberInStock)
{
modelNumber='g-20';
ftr=new list<fridge.RareFridge>();
this.numberInStock=numberInStock;
}
public list<Fridge.RareFridge> updateStock(Integer justSold)
{
numberInStock = numberInStock - justSold;
System.debug('The number in stock r es'+numberInStock);
ftr.add(new Rarefridge(20,'Gret'));
return ftr;
}
public class RareFridge
{
//publi items {get;set;}
Integer i;
String str;
public RareFridge(integer g,String str)
{
This.i=g;
this.str=str;
}
}
}
running from annonymous block
for(integer h=0;h<10;h++)
{
Fridge f=new Fridge(200);
}
public List<fridge.rarefridge>t;
t=f.updateStock(50);
for(fridge.Rarefridge m:t)
{
//System.debug('The vlue of is'+m.i);
}
om sai 10
I got it