显示我从类中获得的数组 [英] Display the arrays i get from classes

查看:126
本文介绍了显示我从类中获得的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我不想告诉我关于抽象类,继承每一个。它只是Stereo,Ygro,Aerio类,它们像公共类Stereo {// code inside}一样开始没有任何类。我想要这样的方式我的主要类名为Ekset1,调用这3个类,以便在一个数组中获取它们。数组的长度我给出键盘A的长度它可以是每个数字但大于3 ,因为直到3它将从那些类中取出那些插槽。如果这种情况发生在正常的类中,那么请用继承抽象主类来解决它。我希望你理解我。最后这将完成显示所有这三个类的数组

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
}


推荐答案

已编辑:

Food[] pin = new Food[A];

这是一个类型为Food的数组。它可以容纳食物类型和其他类型的食物(比萨饼,玉米,马铃薯),从食物延伸。例如,如果您没有从Food扩展Stereo类,则无法在此数组中存储它的任何实例。

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

这篇关于显示我从类中获得的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆