[Skip Navigation] [CSUSB] / [CNS] / [CSE] / [R J Botting] /[CS320 Course Materials] /15q.html [15q.txt(Text)] [Search ]
Fri May 18 10:27:12 PDT 2012
[Schedule] [Syllabi] [Text] [Labs] [Projects] [Resources] [Grading] [Contact]
Notes: [01] [02] [03] [04] [05] [06] [07] [08] [09] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20]

Contents


    CS302/15 Questions on OO and Java

      Question 1 Basic OO Knowledge

      a. What is a class, what is an object, and what is the relation between an object and its class?

      b. Which UML class diagram below shows a class and which an object?

      [A] or [:B]?

      c. Describe the differences between an instance variable and a class variable.

      d. Fill in the blanks: Object-Oriented programming differs from using data abstraction because OO uses (1) i___________________ and (2) p_________________.

      e. Describe over-riding.

      Warm Up Stretch

      Hello2 extends Hello1
       	/** Simplest demo of polymorphism
       	*/
       	import java.lang.*;
       	class Hello1 {
       	    public void print(){
       	        System.out.println("Hello1");
       	    }//Hello1.print
       	}//class Hello1
      
      
       	class Hello2 extends Hello1{
       	    public void print(){
       	        System.out.println("Hello2");
       	    }//Hello2.print
      
      
       	    public static void main(String argv[]){
       	        (new Hello1()).print();//which print do we get?
       	        (new Hello2()).print();//which print do we get?
      
      
       	        Hello1 hiThere = new Hello2();
       	        hiThere.print();//which print do we get?
       	    }//main
       	}//class Hello2

      Answer: Try it in the lab!

      Warm Stretch Part 2

      I translate the above Java into C++ in the obvious way (see below), compile it, and run it. What happens?

       	/* Simplest demo of polymorphism:  Hello1.cpp
       	*/
       	#include <iostream>
       	using namespace std;
      
      
       	class Hello1 {
       	public:
       	     void print(){
       	        cout <<"Hello1"<<endl;
       	    }//Hello1.print
       	};//class Hello1
      
      
       	class Hello2:public Hello1{
       	public:
       	    void print(){
       	        cout <<"Hello2"<<endl;
       	    }//Hello2.print
       	};//class Hello2
      
      
       	int main(){
       	        (new Hello1())->print();//which print do we get?
       	        (new Hello2())->print();//which print do we get?
      
      
       	        Hello1 * hiThere = new Hello2();
       	        hiThere->print();//which print do we get?
       	}//main

      Suprise! Try it in the lab.....

      I add the reserved word "virtual" as shown below, compile it, and run it. What happens?

       	/* Simplest demo of polymorphism:  Hello1.cpp
       	*/
       	#include <iostream>
       	using namespace std;
      
      
       	class Hello1 {
       	public:
       	     virtual void print(){
       	        cout <<"Hello1"<<endl;
       	    }//Hello1.print
       	};//class Hello1
      
      
       	class Hello2:public Hello1{
       	public:
       	    void print(){
       	        cout <<"Hello2"<<endl;
       	    }//Hello2.print
       	};//class Hello1
      
      
       	int main(){
       	        (new Hello1())->print();//which print do we get?
       	        (new Hello2())->print();//which print do we get?
      
      
       	        Hello1 * hiThere = new Hello2();
       	        hiThere->print();//which print do we get?
       	}//main

      The above works just like the first Java program.....

      The above exercises demonstrate P____________________________.

      To show polymorphism you need at least some inheritance and a pointer to a general class that can point at a concrete class and has the specialized behavior.

      Question 2 Abstraction

      a. Define a concrete class and an abstract class (one sentence each).

      b. What is an interface?(one sentence)

      c. Show how an abstract class, an interface, and a client using an interface are drawn in the UML.

      Answer: [ ole2.gif ]

      d. What can you do with a concrete class that you cannot do with a more abstract class? (sentence)

      [ ole3.gif ]

      Question 3 Polymorphism

      a. Describe polymorphism.

      b. Define and explain the differences between: static binding and dynamic binding of methods.

      c. To get polymorphism which method binding do you need: static or dynamic?

      d. What word is used to get dynamic binding in C++? Fill in the blank: v_____________.

      d. Give C++ code that gives different answers depending only on whether dynamic binding is used.

      e. In Java, are methods polymorphic or not? Do you have a choice? If so, how do you exercise your choice?

      Question 4 Java

      a. What is Java?

      b. Give a short history of Java.

      c. What questions would a typical C++ programmer ask when they start learning Java?

      d. In Java what are the differences between an application and an applet? (short 4 sentence essay)

      Question 5 OO Issues

      List and describe the design issues for Object-Oriented programming languages.

      Question 6 History of OOPL

      Write a brief history of Object-Oriented programming including dates and names of languages and people.

      Question 7 History of OOPL

      Draw a time-line(picture) of the development of Object-Oriented programming.

    Review

End