For example I have this classes:
public class Car{
public string color;
public double price;
}
public class YellowCar{...}
public class RedCar{...}
and in the class Car I want to write a method that would display information about "inherited" fields from his derived classes so it would look like this:
public class Car{
public string color;
public double price;
public void DisplayMethod(){
//display field **color** and field **price** from the instance of the YellowCar class
//...then display the same fields from the instance of the RedCar class
}
}
I don't wanna use a method that would take a derived class instance as a parameter and display its fields so I need to invoke this method a couple of times for every instance. Is there an option in program architechture to write something close to the method i've mentioned before? And if it is what does it is and how does it works?
Aucun commentaire:
Enregistrer un commentaire