CSCE 156 PreTest

 

January 11, 2007

 

 

This examination consists of 28 multiple-choice questions and you have 30 minutes to complete the test. 

 

Please read every question carefully.  If you have questions, please raise your hand and I will come to you. 

 

 

1.         What is the relationship between a class and an object of that class?

 

  1. A class is a kind of mold or template that dictates what objects can and cannot do.
  2. An object is the same as a class.
  3. A class is an instance of an object. 
  4. A class is like CSCE156 and an object is like a student registered in CSCE156.

 

 

2.         Which of the following is not a class-object pair?

 

  1. Robot – R2D2
  2. Car – Toyota
  3. Course – CSCE156
  4. Parking Lot – Car-1

 

 

3.         Which statement is not true in the following?

 

  1. A method is like what somebody can do, and a message is like what I, as a programmer, can send to that somebody to ask that somebody to perform that method.
  2. To instruct a class or an object to perform a method, we send a message to it.
  3. Messages are the input and output of a method.

 

 

4.         What is object-oriented programming?  (Choose the best answer.)

 

  1. It’s about solving problems modularly.
  2. It’s about defining classes (molds!), instantiating objects from these classes, and asking these objects to interact and do things for us.
  3. It’s about defining the objectives of each component in the program, resolving conflicts among the objectives, implementing them in classes, and instantiating objects from these classes to solve problems.

 

5.         What does a class have?

 

I.    Data values                        II.   Methods

III.  Objects                             IV.  Arguments

 

  1. II & III
  2. I, II, & III
  3. I & II
  4. I, II, III & IV

 

 

6.         Which of the following is not true about a class method and an instance method?

 

  1. A class method is one that a programmer can use without having to instantiate an object of that class
  2. An instance method is one that a programmer can only use by asking an instantiated object of that class to do
  3. A method that deals with collective information about the instances of a class is usually defined as class method.
  4. A method that deals with a particular individual instance is called an instance method.
  5. A, B, C, and D are false.

 

 

7.         What is the order of the Software Engineering phases?

 

  1. Design, Analysis, Coding, Testing, Operation (Maintenance)
  2. Analysis, Design, Coding, Testing, Operation (Maintenance)
  3. Coding, Analysis, Design, Testing, Operation (Maintenance)
  4. Design, Analysis, Coding, Operation (Maintenance), Testing

 

 

8.         Which of the following is not true about a “main” or “application” Java class?

 

  1. A “main” class can be invoked/run as an application.
  2. A “main” class does not have a class definition.
  3. A “main” class has a “main” method.
  4. A “main” class uses other basic classes

 

 

 

 

 

 

 

 

9.         Assuming that the class Ewok has been correctly implemented, will the following code compile?

 

class TestEwok  {

    public static void main (String[] args) {

         Ewok myEwok1;

         myEwok1.printInfo();

    }

}

 

  1. Yes
  2. No

 

 

10.       In Java, given x = 10, y = 7, z = 2.5, what is the value of the following expression?

 

x+3 / y +z * x%2

 

  1. 10
  2. 11.4286
  3. 11
  4. 11.0
  5. 10.4286

 

 

11.       Which of the following statements are true?

 

I.    Usually, a data member of a class is declared “private.”

II.   Usually, a method of a class is declared “public.”

III. Methods that client programmers do not need to know about or do not need to use should be declared “private.”

IV. Sometimes, data members such as constants are declared “public” so that client programmers could access them (since constants cannot be modified).

 

  1. I & II only
  2. I, II, & III only
  3. I, II, III, & IV
  4. I, II, & IV only

 

 

 

 

 

 

 

 

12.       What is the output of running TestJedi?

 

class Jedi {

    private String name;

    private double level;

   

    public Jedi()  {

         name = “pupil”;

         level = 0;

         }

 

    public void setLevel(double x)  {

         int level;

         level = x;

    }

 

   public double getLevel()  {

         return level;

    }

 

}

 

class TestJedi {

     public static void main(String[] args)  {

          Jedi apprentice1 = new Jedi();

          apprentice1.setLevel(0.5);

          System.out.println(apprentice1.getLevel());

    }

}

 

  1. 0.0
  2. 0.5
  3. undefined

 

 

13.       What is overloading a method?

 

  1. Invoking a method with too many arguments
  2. Defining multiple methods with the same method name but with different parameters (and implementations)
  3. Defining the Constructor method such that it invokes other methods
  4. Defining the Constructor method such that it instantiates other classes

 

 

 

 

14.       Which of the following is not true about a local variable?

 

  1. A variable declared within the method declaration is called a local variable.
  2. Local variables are used for temporary purposes, such as storing intermediate results of a computation.
  3. Local variables can be accessed from outside the method through an instance of the class to which the method belongs.
  4. Local variables are erased when the execution of a method is completed.

 

 

15.       Given the if statement shown, what is the output when x = 2, y = 5, and z = 3?

 

output = 0;

if ( x >= 3)

   output = 5;

else if (y < 4 && z < 3)

   output = 6;

else if (z >= 3) {

   output = 7;

   if (y < 4)

      output = 8;

   }

 

  1. 0
  2. 5
  3. 6
  4. 7
  5. 8

 

 

16.       Which of the following is not true about pre-test and post-test loops?

 

  1. While loops are pre-test loops
  2. For loops are pre-test loops
  3. Do-while loops are post-test loops
  4. A post-test loop executes the body of the loop at least once
  5. A pre-test loop is exactly the same as a post-test loop in terms of functionality and logic

 

 

 

 

 

 

 

 

 

17.       Which of the following is not true about count-controlled and sentinel-controlled loops?

 

  1. For loops are the natural implementation choice for count-controlled loops
  2. While loops are the natural implementation choice for sentinel-controlled loops
  3. If one knows exactly the number of iterations for a loop, then one should use a count-controlled loop
  4. If the number of iterations for a loop depends on certain condition or event becoming true, then one should use a sentinel-controlled loop
  5. A loop cannot be both count-controlled and sentinel-controlled

 

 

18.       Given the while statement shown, what is the equivalent for loop implementation?

 

int j = 0;

while ( j < 10)  {

   j = j + 2;

   int i = j;

   while (i < 20)  {

       i = i + j;

       }

   }

 

      A.        for (int j = 0; j < 10; j = j+2)

                        for (int i = j; i < 20; i = i+j); 

        

      B.         for (int j = 0; j = j+2; j < 10)

                        for (int i = 0; i < 20; i = i+j);

 

C.                 for (int j = 0; j < 10; j = j++) {                  

                  j = j + 2;

                        for (int i = j; i < 20; i++)  {

                            i = i + j;

                        }

                  }

 

 

19.       Which of the following is not pertinent to the delegation-based event model in Java?

 

  1. Event sources
  2. Event handlers
  3. Event listeners
  4. Event performers

 

 

 

 

20.       Which of the following must be done to build an effective Java GUI?

 

I.  Declare and create event sources

II. Associate an event listener to each event source

III. Handle each event that requires response

IV. Implement ActionListener

 

  1. I and II
  2. I, II, and III
  3. I, II, and IV
  4. I, II, III, and IV

 

 

21.       Why do we want to use exception handling in our programs?  (Choose the best answer)

 

  1. To make the programs easier to debug
  2. To make the programs more reliable/robust
  3. To get the programs to compile

 

 

22.       Which of the following is not true?

 

  1. An exception represents an error condition that can occur during the normal course of program execution.
  2. When an exception occurs, we say that an exception is thrown.
  3. When the matching exception-handling code is executed, we say that the thrown exception is caught. 
  4. When an exception occurs, the normal sequence of flow continues but the exception-handling routine is also executed.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

23.       What is the output of this try-catch block if inputStr is “1000”?

 

try {

   num = Integer.parseInt(inputStr);

   if (num > 100)

      throw new Exception (“Too Large”);

}  catch (NumberFormatException e) {

   System.out.println(“Cannot convert.”);

}  catch (Exception e)  {

   System.out.println(e.getMessage());

}  finally {

   System.out.println(“Done”);

 

I.  “Too Large”

II.  “Cannot convert”

III.  A Java-specific exception message

IV.  “Done”

 

  1. I
  2. I & IV
  3. II & IV
  4. III & IV

 

 

24.       What are the values of persons[0] and persons[1]?

 

int persons[10];

persons[0] = 1;

persons[1] = 2;

int temp = 3;

temp = persons[0];

persons[0] = persons[1];

persons[1] = temp;

 

  1. 1, 2
  2. 2, 3
  3. 1, 3
  4. 2, 1
  5. 3, 1

 

 

 

 

 

 

 

25.       Which of the following is not true about binary search?

 

  1. Its complexity is O(n)
  2. It runs faster than a linear search
  3. The list of elements involved has to be sorted first
  4. If there are 8 elements (numbers) in the list, in the worst case scenario, the search needs to look at only 3 elements to determine whether a user-specified element is in the list

 

 

26.       Which of the following is not a benefit of using Inheritance?

 

  1. Better organization of different but related classes
  2. More efficient coding
  3. Easier to maintain
  4. Can make use of polymorphism
  5. Can increase the amount of duplicated code

 

 

27.       Which of the following is not correct?

 

  1. Common data members of subclasses should be declared as data members of the superclass
  2. The subclasses of a superclass should cover all possible instances of that superclass
  3. To use polymorphism effectively, all subclasses and the superclass should share the same “behavior” even though how the “behavior” is actually carried out can be different

 

 

28.       If s is “lincoln”, what is the output of the mystery function?

 

function mystery(String s)  {

  

    if (s is an empty string) 

       print(“”)

    else  {

print(first char of s)

print(last char of s)

mystery(s without 1st and last chars)

      }

 

}   // end function

      

  1. linccoln
  2. lnilnocc
  3. lliinnccoollnn
  4. lincolnnlocnil