1. The document provides examples and questions about object-oriented programming concepts like classes, objects, constructors, and associations.
2. It asks the reader to identify classes and objects from code snippets, write constructor signatures, and create objects by calling constructors. Mistakes are pointed out like using the wrong parameter types.
3. Common relationships are explained like a class being like a cookie cutter and an object being like an individual cookie, and that a class can have many objects but an object only belongs to one class.
1. The document provides examples and questions about object-oriented programming concepts like classes, objects, constructors, and associations.
2. It asks the reader to identify classes and objects from code snippets, write constructor signatures, and create objects by calling constructors. Mistakes are pointed out like using the wrong parameter types.
3. Common relationships are explained like a class being like a cookie cutter and an object being like an individual cookie, and that a class can have many objects but an object only belongs to one class.
1. The document provides examples and questions about object-oriented programming concepts like classes, objects, constructors, and associations.
2. It asks the reader to identify classes and objects from code snippets, write constructor signatures, and create objects by calling constructors. Mistakes are pointed out like using the wrong parameter types.
3. Common relationships are explained like a class being like a cookie cutter and an object being like an individual cookie, and that a class can have many objects but an object only belongs to one class.
int width =13; Rectangle myRect = new Rectangle(length, width); a. Identify the class 5HFWDQJOH b. Identify the object P\5HFW c. What type of parameter(s) are passed to the constructor? GRXEOHLQW 2. Write out the signature for the constructor of the 5HFWDQJOH class from #1 above. SXEOLF5HFWDQJOHGRXEOH[LQW\8VHDQ\QDPHV\RXOLNHLQWKHSODFHRI[DQG\ 3. Suppose a constructor for the /XQFK class is as follows: public Lunch(boolean diet, int cal) { diet_yes_no = diet; calories = cal; } Write appropriate code that will create a /XQFK object called \XPP\. You should tell the constructor that, yes, you are on a diet, and the number of calories should be 900. /XQFK\XPP\ QHZ/XQFKWUXH
4. BankAccount account39 = new BankAccount(500.43);
a. Identify the class %DQN$FFRXQW b. Identify the object DFFRXQW c. What type of parameter(s) are passed to the constructor? GRXEOH 5. A class is like a FRRNLHFXWWHU. An object is like a FRRNLH. Fill in the blanks above using the word cookie and cookie cutter. 6. Whats wrong (if anything) with the following constructor for the 6FKRRO class? public void school(int d, String m) { some code } YRLGVKRXOGEHRPLWWHGDQGVFKRROVKRXOGKDYHDFDSLWDO6 7. Which of the following is a correct association? D 2QHFODVVPDQ\REMHFWV b. One object, many classes 8. Which must exist first? D7KH FODVV b. The object 9. Is the following legal? If not, why? //This code is in PDLQ of 7HVWHU class //Constructor int p = 3, q = 9; public House(int j, boolean k) House myHouse = new House(p, q); 1RWKHVHFRQGSDUDPHWHUTVKRXOGEHDERROHDQ { some code }