







Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A part of the cs61b lecture notes on object-oriented mechanisms in java. It covers topics such as overloading, generic data structures, dynamic vs. Static types, type hierarchies, the basic static type rule, consequences of the compiler's 'sanity checks', overriding and extension, and illustrations. The lecture also includes examples and explanations of various concepts.
Typology: Slides
1 / 13
This page cannot be seen from the preview
Don't miss anything!








Public Service Announcement:
Readings:
Today:
Object[] things = new Object[2]; things[0] = new IntList (3, null); things[1] = "Stuff";
Object[] Object Object
Object[] Object[]
3
IntList "Stuff"
String
int
IntList
int IntList
String ???
static type
container
dynamic type value
int double boolean ... Object
Integer Double Boolean String IntList int[] Object[] ... String[]
is a (un)wraps to
class Worker { void work () { collectPay (); } }
class Prof extends Worker { // Inherits work () }
class TA extends Worker { void work () { while (true) { doLab(); discuss(); officeHour(); } } }
Prof paul = new Prof (); | paul.work() ==> collectPay(); TA mike = new TA (); | mike.work() ==> doLab(); discuss(); ... Worker wPaul = paul, | wPaul.work() ==> collectPay(); wMike = mike; | wMike.work() ==> doLab(); discuss(); ...
Lesson: For instance methods (only), select method based on dynamic type. Simple to state, but we’ll see it has profound consequences.