Skip to content

Accessing subclass properties

Gordana Sretenovic

Asked Nov 2, 2013, 11:36 AM EDT1 answer
Share
LinkedInX
 

I have a base class called StockItem and one called EcoStockItem and a Plate subclass. EcoStockItem has a Juice object that is a subclass to EcoStockItem. In another class, I have the method AddItem (StockItem p). From the Form1 class should I send the StockItem item as a parameter to the method AddItem? I could not access the other property from subclasses. How should I do it? Create an object of StockItem to inherit all properties from subclasses and add it to a StockItem array?

            

 

 

Java
 newStockItem = new StockItem();






            newStockItem.Id = id;

            newStockItem.Name = name;

            newStockItem.StockCount = stockcount;

            newEcoStockItem =new EcoStockItem ();





            newEcoStockItem.Markning = markning;

            newPlate = new Plate();






newPlate.Typ = typ;

            newJuice = new Juice();







            newJuice.Typ = jtyp;



//  StockItem p = ????







Stock stock = new Stock();



            stock.AddItem(p);



 



 

and method: 

 

 

 

public StockItem[] StockItems = new StockItem[10];

 

 

Code
public void AddItem(StockItem item)



        {



int index = GetCount();



            StockItems[index] = item;



Form1.myForm.textBoxTest.Text = StockItems[index].ToString();



        }

 


 

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 1 short reply