by
PRO
FE S
S OR

QUIZ for SECTION IX
To find an answer, click on the desired question.
QUESTION 1:
QUESTION 2:
Write the Constructor for this class that initializes that 'test' Object to a given
'numberQuestions' when created.
class Quiz
{
public static void main(String[] args)
{
///// The Constructor is placed here. //////
QUESTION 3:
What would you need to add in your code in order to do that ?
QUESTION 4:
Examine the class below:
class Student
{
String name;
// Constructors are placed here.
Write those Constructor for each case above.
ANSWER to QUESTION 1:
Also Constructors are helpful for interaction among Objects.
ANSWER to QUESTION 2:
{
// A value is passed as an argument in the Constructor: 'tmpNumber'
// Then the Instance variable 'numberQuestions' is set to that value.
ANSWER to QUESTION 3:
Quiz()
{
}
If the default Constructor is not explicitly written, a compiler error would occur. In this case, as we have already a
parameter Constructor, the default Constructor is not automatically implemented. It would have to be explicitly written.
ANSWER to QUESTION 4:
// Constructor for the 'age' Variable:
Student(int tmpAge)
{
// Constructor for the 'name' Variable:
Student(String tmpName)
{
// Constructor for the 'age' and 'name' Variables (in that order):
Student(int tmpAge, String tmpName)
{
name = tmpName; // name assigned
// Constructor for the 'name' and 'age' Variables (in that order):
Student(String tmpName, int tmpAge)
{
name = tmpName; // name assigned