CSE 8B Chapter Notes - Chapter 13.5 - 13.6: Generic Programming

24 views2 pages

Document Summary

Interfaces are class-like constructs that contain constants and abstract methods. Goal of an interface it to define common behavior for related and unrelated classes. Syntax for declaring an interface accessmodifer interface interfacename { Can use as a data type for reference variables. Cannot create an instance from an interface with new operator. Relationship between class and interface == interface inheritance. Class implementing interface will implement all method signatures in that interface. Comparable interface defines compareto method for comparing objects. Comparable interface definition package java. lang public interface comparable { public int compareto(e o); Compareto method determines order of this object with object o: returns negative, 0, or positive integer if this is less than, equal to, or greater than o, respectively. Comparable interface is generic: generic type e replaced by concrete type when implementing this interface. To implement an interface, use the keyword implement public class foo implements bar { The class called foo implements the interface called bar.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents