views:

93

answers:

2

you have

public class Question

and

public class MultipleChoice extends Question

and

public class SurveyQuestions

where SurveyQuestions has

private static List<Question> q = new ArrayList<Question>();

In main you keep adding questions and all the things questions are composed of to the list.

Once done, you want to iterate over the list

for (Question q : SurveyQuestions.getInstance().getListOfQuestions())

Question: What type should "q" be so that it has access to both Question and MultipleChoice?

+2  A: 

If by "access to" you mean "access to the methods of"- you can't have it as MultipleChoice because some questions might not be such. So it has to be Question, and then you can check if it is a multiple-choice by if(q instanceof MultipleChoice)

Bozho
Perfect. Thank you
mac
+1  A: 

You should make it Question.

You can't make it MultipleChoice as a plain Question is not a MultipleChoice... but a MultipleChoice is a Question. So Question can represent both types.

froadie