Helsingin yliopisto / Tietojenkäsittelytieteen laitos / 581258-1 Johdatus ohjelmointiin
Copyright © 1997 Arto Wikla. The use of this material is only allowed for studying purposes of private persons. Any other use of this material, such as commercial or other courses, is forbidden.


581258-1 Introduction to Programming: 2. exam 18.12.1997/AW

Please write on the top of each of your papers the name of the course, the date of the exam, your name, your date of birth and your signature.

You may use the tools of the Lue-class when writing your programs.

  1. Compare the following concepts concisely and precisely:
  2.    primitive type - reference type
       compilation unit - package
       instantiation (creating an object) - class loading
                                                                  (6 points)
  3.                                                          (5 points)
    
  4. Class Example is defined as follows:
  5.   public class Example {
        public int[] iT;
        static private double d;
        public Example() {
          iT = new int[10]; d = 3.14;
        }
        void metA() {
          System.out.println(iT.length);
        }
        public int metB(int par) {
          return iT.length+par;
        }
        static String metC(char c) {
          return ""+d+c;
        }
      }
    

    Write a subclass Sub for the class Example. Sub must hide the field d, override the method metC, inherit the method metB and overload the method metA.What is the easiest way to use the hidden, overridden, inherited, and overloaded parts in class Sub? Or is it possible to use them?

                                                                  (5 points)
    
  6. Explain the scope rules of Java. What scope areas there are, and how the visibility (usability) of names (identifiers) is controlled? When a name "Name" is used inside a method, from where and in what order the meaning of the name is searched?
  7.                                                               (5 points)
    
  8. You are given a class called InpFile for reading an input file. The class has a constructor:
  9. The class contains a method for reading lines:

    By using this class, write a program that asks the user for the name of the input file, a character to be replaced (oldChar), and a replacing character (newChar). Then the program prints the file, modified so that all oldChar-characters are replaced by the newChar-character.

                                                                  (5 points)