1 - Classes - OOP Question Sheet
Philip Peng
2007/09/14
Mr. Benum
Created in Notepad++


Interface of Objects:

1. Why hide the data within objects?
	Protects object's data from being read and accessed by the client code.
   
2. What changes do you see with the data encapsulated in the PhoneBook object and the PhoneBook2 object?
	In the original, all the object's data is kept in a limited array, but in PhoneBook2, limitless vectors are used instead.

3. What method encapsulated in the PhoneBook2 object could be improved so that it works more efficiently, but doesn't affect the classes that may use the PhoneBook2 object?
	ArrayLists could have been used instead of vectors, allowing for the use of pre-programmed arraylist functions (ie use .indexOf() instead of coding a find() method).


Classes:

1. What is a class? Describe it in your own words.
	A class is a type of category from which objects with specific properties are constructed.

2. What does the word instantiation mean?
	Gives/sets up an object/variable a value

3. What does a constructor do?
	Creates an object/variable of a certain class/type.

4. Is it possible for a class to have no constructor? How does that work? Can a class have more than one constructor? Can it have multiple constructors with the same number of arguments? What if these arguments were of the same type?
	No, all classes do not need to have a constructor. For example, the Math class gives methods rather than creating an object. A class can also have more than one constructor through overloading but only creates one type of object. If the arguments for the overloading are all the same, however, there will be a compiling error.


5. If we had a class Widget, how would I instantiate a new object of that type called w1? Be sure to distinguish between the two steps that are really going on here.
	Widget w1;
	w1 = new Widget(arguments);

6. How would you call the start method of the newly created object?
	w1.start();


7. If two Widget objects exist, w1 and w2, and they have instance fields (colour and name), when would the boolean expression (w1 = = w2) evaluate as true?
	Since "==" is for reference points, it would not evaulate as true unless there is a line "w2 = w1;". "w1.equals(w2);" should be used.


8. What about in this situation, where String s1 = "bob"; and String s2 = "bob"; does (s1 = = s2) evaluate as true?
	No since they are separate objects.


9. How would you properly test for equality of two string objects?
	"s1.equals(s2);"


Note: From question 7, if you use the statement w1 = w2, this does not make w1 object a copy of w2. Instead, they point to the same object.



