MUSICAL COMPOSITION:
Carmina Burana,
O Fortuna,
Carl Off
03:04 |
At the end of today's class you should
HAVE READ:
KNOW:
BE ABLE TO:
DAILY QUESTION:
package p1; public class Sample { public int a; protected int b; private int c; int d; public static int e; |
package p2;
public class DerivedSample extends Sample
{
|
Which of these variables (both instance and static) are visible within the doSomething() method?
Sample Exam question(s)
1. A library has a number of items that can be borrowed. The following table describes the situation
Item | Behavior |
LibraryItem | Every library item, by default, can be borrowed freely for 14 days. Each item has a name and a UPC code. |
VHS Video | Videos cost $1.00 to borrow, and must be returned within 7 days. |
DVD Video | DVD videos cost $2.00 to borrow, and must be returned within 7 days. Note that some DVDs come with multiple disks. |
Reference | Reference materials, such as Encyclopedias and Dictionaries, cannot leave the library and can only be borrowed freely for 2 hours at a time. |
Magazines | Magazines cannot leave the library, but they can be borrowed freely for up to 8 hours |
NYTimes BestSeller | NYTimes Best Seller books can be borrowed freely, but must be returned within 3 days |
Design a set of classes that captures the relationships between the base class LibraryItem and its five derived classes.
2. You are given a base class B, a derived class C, and a method m of the derived class C.
2a) You are told that method m
is an overloaded method. Explain what this means in relation to either class B
or C.
2b) You are told that method m overrides another
method n. Explain what this means in relation to either class B or C.
3. You are asked to design a class representing a Rectangle. You are given a Point class that represents int x and y values in the plane. Design the constructors for the Rectangle class so that you can:
3a) Create a rectangle given two points
(an upper left corner and a lower right corner)
3b) Create a rectangle given four int values (x1,y1,
x2,y2)
3c) Create a degenerate rectangle given just a point (thus it
is both upper left and lower right)
3d) Create the default rectangle whose coordinates represent
the (0,0,0,0) rectangle
make sure you use the this() construct, with suitable arguments, when designing these constructors.