August
    1999 QUESTION 1 (Compulsory) Total Marks: 20 Marks  | 
    Click here to access other
    questions
     SUGGESTED SOLUTIONS  | 
  
| (a) | (i) Explain what is meant by the term Java
    Virtual Machine. (ii) Explain why the concept of the virtual machine aids the portability of code.  | 
    [3] [2]  | 
  
(i) The Java Virtual
    Machine is 
 
  | 
    ||
(ii) Portability is
    easier because
 
  | 
    ||
| (b) | Java is an Object Oriented
    programming language. Explain what is meant by the following terms in the context of
    object oriented programming: (i) Encapsulation (ii) Inheritance (iii) Overloading  | 
    [1] [1] [1]  | 
  
| (i) Encapsulation is
    when data and methods operating on that data are described in the same structure. 
  | 
    ||
| (ii) Inheritance is
    when a new data type of created which incorporates all the members of a parent data type. 
  | 
    ||
| (iii) Overloading is
    when two methods in a class have the same name, but different parameterizations. 
  | 
    ||
| (c) | Identify the difference between a class and an object. | [2] | 
 
  | 
    ||
| (d) | (i) Define a public java class MyAddress, which contains 2
    member variables, HouseNumber, which is an integer, and StreetName, which is a string. (ii) Write a constructor function for your class, which will take in two parameters that will initialize the member variables of your class. (iii) Write a function ShowMeHome, which is a public member of your class MyAddress, with a void return type, which will print out the values of HouseNumber and StreetName. (iv)Write a small fragment of Java code which will construct an object of type MyAddress, and cause it to print out its members.  | 
    [3] [2] [3] 
  | 
  
| (i) A sample
    definition of MyAddress follows : public class MyAddress { 
  | 
    ||
| (ii) A sample
    definition of MyAddress constructor follows: MyAddress (int num, String Street) { 
  | 
    ||
| (iii) A sample
    definition of ShowMeHome follows: void ShowMeHome( ) { 
  | 
    ||
| (iv) A sample
    definition of the code follows: MyAddress MyHome - new MyAddress (1, "my address"); 
  |