Chris Pollett >
Old Classes >
CS151

   ( Print View )

Your Grade: Course Info: Homework Assignments: Practice Exams:
                            












CS 151 Practice Midterm

Return to classpage

The practice midterm is below. Here are some facts about the actual
midterm: (a) The midterm will be in class Oct. 17. (b) It is closed 
book, closed notes. Nothing will be permitted on your desk except 
your pen (pencil) and test. (c) You should bring photo ID. 
(d) There will be more than one version of the test. Each version 
will be of comparable difficulty. (e) If your cell-phone or beeper 
goes off you will be excused from the test at that point and graded 
on what you have done till your excusal.

(1) Draw UML diagrams that express the following concepts:
    (a) Class C and class B are subclasses of class A.
    (b) Class P has two private fields int x and int y and one 
        public method setXY(int x1, int y1)
    (c) bob is and object of class Bob.
    (d) Class A objects contain one or more objects of class B.
    (e) Interface A is implemented by class B and class C.

(2) Define the following computer science terms:
    (a) Primitive type
    (b) type conversion
    (c) narrowing / widening a type.
    (d) reference type 
    (e) type casting

(3) (a) Give an example of variable shadowing.
    (b) (2pts) Explain the difference between method hiding and 
        overriding methods.
    (c) Give an example of marker interface.
    (d) Suppose class A implements two interfaces C and D. Each of these
        has a method public void getRichQuick() but C's method
        throws CaughtBySECException and D's method throws 
        AntitrustException. What will the compiler do?

(4) (a) With respect to subclassing what does restriction mean?
    (b) How do we implement restriction in Java?
    (c) Suppose we have two interfaces in Java: I2 which extends
        I1. Is I2[] a subtype of Object[]? Why or why not?
    (d) What is multiple inheritance?
    (e) Give a way to achieve the effect of multiple inheritance in Java. 
        

(5) (a) In a Java class definition what is an initialization. Give an 
         example.
    (b) Give the order in which the following three things would be
        initialized when a subclass B of class A is created: 
        (i) an explicit initializer in B, (ii) an explicit initializer 
        in A, and (iii) an initalization statement in a constructor of A. 
    

(6) (a) On what methods and classes should one use /** ...  */ comments?
    (b) For javadoc to detect these comments where relative to these
        methods/classes should the comment occur?
    (c) Explain how to use each of the following javadoc tags:
        (i) @since (ii) @see (iii) @param

(7) Define the following terms with respect to their object-orientation
    meaning. Give an example of (b) and (c). 
    (a) framework
    (b) idiom
    (c) design pattern


(8) Give each of the things needed for the canonical form for public classes
    in Java.

(9) Class A and Class B each contain identical blocks of code 30 lines long.
    Class A extends Class C and Class B extends Class D. Suggest a way to
    avoid the code duplication using factorization. What kind of
    factorization did you use?

(10) Give the UML diagrams for the folowing design patterns: 
     (a) Strategy
     (b) Iterator
     (c) Factory
     (d) Template
     (e) Singleton