Top Banner
CSS446 Spring 2014 Nan Wang
10

CSS446 Spring 2014 Nan Wang. To be able to declare and use interface types To appreciate how interfaces can be used to decouple classes To learn.

Jan 02, 2016

Download

Documents

Marshall Hill
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: CSS446 Spring 2014 Nan Wang.  To be able to declare and use interface types  To appreciate how interfaces can be used to decouple classes  To learn.

CSS446Spring 2014

Nan Wang

Page 2: CSS446 Spring 2014 Nan Wang.  To be able to declare and use interface types  To appreciate how interfaces can be used to decouple classes  To learn.

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

Page 3: CSS446 Spring 2014 Nan Wang.  To be able to declare and use interface types  To appreciate how interfaces can be used to decouple classes  To learn.

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

Page 4: CSS446 Spring 2014 Nan Wang.  To be able to declare and use interface types  To appreciate how interfaces can be used to decouple classes  To learn.

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

Page 5: CSS446 Spring 2014 Nan Wang.  To be able to declare and use interface types  To appreciate how interfaces can be used to decouple classes  To learn.

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

Page 6: CSS446 Spring 2014 Nan Wang.  To be able to declare and use interface types  To appreciate how interfaces can be used to decouple classes  To learn.

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

6

Page 7: CSS446 Spring 2014 Nan Wang.  To be able to declare and use interface types  To appreciate how interfaces can be used to decouple classes  To learn.

7

Page 8: CSS446 Spring 2014 Nan Wang.  To be able to declare and use interface types  To appreciate how interfaces can be used to decouple classes  To learn.

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

8

Page 9: CSS446 Spring 2014 Nan Wang.  To be able to declare and use interface types  To appreciate how interfaces can be used to decouple classes  To learn.

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

Page 10: CSS446 Spring 2014 Nan Wang.  To be able to declare and use interface types  To appreciate how interfaces can be used to decouple classes  To learn.

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