CIS191-S09/Slides and Notes/February 9 - 13

From MCIS Wiki

Jump to: navigation, search

Feb 9

Sample array quiz:

1. Show the contents of “a” after each of the following:

   int a[] = new int[5];
   for (int i = 0; i < 5; i++)
     a[i] = i+1;
   for (int i = 0; i < 5; i++)
       a[i] = i;
   a[0] = 2; a[1] = 4;
   for (int i = 0; i < 5; i++) 
     a[i] = i;
   for (int i = 1; i < 5; i++)
     a[i] = a[i-1] + a[i];
   for (int i = 0; i < 5; i++)
     a[i] = i-1;
   for (int i = 1; i < 5; i++)
     a[a[i]] = a[a[i]] + 1;

2. Suppose that array a is a 2 dimensional array of size 4 x 4 with all 0’s in it. What will the array have in it after each of the following (each of these starts with the array of 0’s)

 for (int i = 0; i < 4; i++)
    for (int j = i; j  4; j++)
      a[i][j] = 1;
 for (int i = 0; i < 2; i++) {
   a[i][0] = 1;
   for (int j = 0; j < 2; j++)
      a[i+1][j+1] = 2; }
 x = 0;
 for (int i = 0; i < 4; i++)
   for (int j = 0; j < 4; j++)
     a[j][i] = x++;

3. Write a method that takes an array of ints and returns the sum of all the ints in the array.

Feb 11

  • What does the book say that the specification of a program will do?
  • What was the difference between the two approaches to the shape / sound program?
  • What is subclassing?
  • How did this get used in the example of Chapter 2?
  • What does “override” mean?
  • What was the basic objection to the non-OO code?
  • What is the difference between a class and an instance?
  • How are classes created? Instances?
  • What is a “launcher”? Have we written launchers in our projects?
  • How would classes for HouseCar and Tiger be related?
  • Can a subclass have methods that are not available to the super class?
  • Can a superclass have methods not in a subclass?
  • Are instance variables inherited?
  • Can they be overridden?
  • Can subclasses have subclasses?
  • If the same method is in more that one class, which one is called when you invoke it?
  • How are “has-a” and “is-a” relations represented in Java?
  • How can you call a method in your superclass if you have your own version of the same method?
Personal tools