University of Ottawa

School of Information Technology and Engineering

CSI1102

 

Quiz 3

 

 

Q1. [2 marks]      Determine the validity of the following statements.

                                          

(T/F)   1. The following declaration is correct: char[][] demo = new char[3][4];

(T/F)   2. The following statement will not generate an error:

 for(int i=0; i<= b.length; i++)  b[i]=1;

(T/F)   3. A method that is declared final can not be overridden in a subclass.

(T/F)    4. An interface can not be inherited.

 

 

Q2. [3 marks]  What does the following program print?

 

public class Messages

{ public static void main (String[] args)

   {  Thought t = new Thought();

      Advice a = new Advice();

      t.message();

      a.message(); 

   }

}

 

public class Thought

{  protected int x = 5;

   public void message()

   {    System.out.println ("Hello!!! x is " + x);    }

}

 

public class Advice extends Thought

{  public void message()

   {

      System.out.println ("Warning!!! x is " + x++);

      super.message();

   }

Text Box: Hello!!! x is 5
Warning!!! x is 5
Hello!!! x is 6
}

 

 

 

 

Last Name:

 

 

First Name:

 

Student number:

 

 

Section: