Reputation:
First,I dont want to tell me about abstract class,inherit each.Its just Stereo,Ygro,Aerio classes that starts like public class Stereo{//code inside } there arent ectended any class.With this way i want in my main class named Ekset1 to call this 3 classes to get them in one array.The array has length i give the length from keyboard A it can be every number but bigger than 3, because until 3 it will take those slots from those classes.If this cant happen with normal classes then please solve it with inherit abstract the main class each.I hope you understand me.In the end when this will done display the array which has all this 3 classes
Food[] pin = new Food[A]; // this the array that include all classes Stereo, Ygro, Aerio
for (int i = 0; i < 3; i++) {
pin[i] = new Stereo(); //this is a class start i=0
pin[i + 1] = new Ygro(); // this is a class
pin[i + 2] = new Aerio(); // this is a class
}
Upvotes: 0
Views: 79
Reputation: 1995
EDITED:
Food[] pin = new Food[A];
This is an array of type Food. It can hold objects of type food and other types of food (pizza, corn, potato), which are extended from Food. If you did not extend your Stereo class from Food, for example, then you cannot store any instances of it in this array.
Look at this tutorial, or find another one on generic inheritance, to help you understand this concept.
http://self-learning-java-tutorial.blogspot.com/2014/03/generics-and-inheritance.html
Upvotes: 1