March 22nd, 2016
Lab
Classwork:
Activity 9: Questions 3 short discussion
Quick Interfaces Review:
• All methods in an interface type are abstract; that is, they have a name, parameters, and a return type, but they don’t have an implementation.
• All methods in an interface type are automatically public.
• An interface type does not have instance variables, but it is legal to specify constants.
How is the correct method executed when the interface method is invoked?
How did the correct method get called if the caller didn’t even know the exact class to which meas belongs?
The Java virtual machine locates the correct method by first looking at the class of the actual object, and then calling the method with the given name in that class.
This means that one method call can invoke different methods depending on the momentary contents of an interface variable. This mechanism for locating the appropriate method is called dynamic method look-up.
Dynamic method look-up enables a programming technique called polymorphism. The term polymorphism comes from the Greek words for “many shapes”. The same computation works for objects of many shapes, and adapts itself to the nature of the objects.
Activity 11 – Simulation of Elevens: Exercises 1, 2 and 3
Homework:
Activity 11: Simulation of Elevens
Exercise 4, and 5
AP Exam 2012 Question 4