css446 spring 2014 nan wang. to be able to declare and use interface types to appreciate how...

10
CSS446 Spring 2014 Nan Wang

Upload: marshall-hill

Post on 02-Jan-2016

214 views

Category:

Documents


1 download

TRANSCRIPT

CSS446Spring 2014

Nan Wang

To be able to declare and use interface types

To appreciate how interfaces can be used to decouple classes

To learn how to implement helper as inner classes

2

Upcasting, can convert from a class type to the type of any interface that the class implements (automatically).

Downcasting, interfaceclasses

If the object(max) doesn’t actually refer to a country, a run time exception will occur.

3

Invoking Methods on Interface VariablesThe 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.

4

A Measurable interface is used to measuring a single object.

The Comparable inter face compares two objects.

Return a negative number if a should come before b, zero if a and b are the same, and a positive number if b should come before a.

Comparable interface

5

Once the BankAccount class implements the Comparable interface, can sort bank accounts array with the Arrays.sort method

6

7

A callback is a mechanism for bundling up a block of code so that it can be invoked at a later time.

8

A class that is declared inside another class is called an inner class.

The inner class is available to all methods of the enclosing class.

Execute file: outerclassName$innerclassName.exe

9

Anonymous object— an object without a name.only used once

Using anonymous class if the class is never used again after a single object of it has been constructed.

10