Lecture6Interfaces

Lecture6Interfaces - Interfaces and Polymorphism Interfaces...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
Interfaces and Polymorphism
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Interfaces A Java interface declares a set of methods and their signatures. Unlike a class, it provides no implementation
Background image of page 2
Signature A method’s signature consists of its name and the types of its formal parameters. An interface signature also includes the method’s return type.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Signature Example: public interface ActionListener { public void actionPerformed (ActionEvent e); }
Background image of page 4
Interface The interface declaration lists all methods that the interface requires .
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
An interface is similar to a class, but All methods in an interface are abstract ; that is , they do not have an implementation All methods in an interface are automatically public. An interface does not have instance variables. You can not create an instance of the interface.
Background image of page 6
implements A class realizes an interface if it declares the interface in an implements clause. implements the method or methods that the interface requires.
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
public class GUI extends JFrame implements ActionListener { …. public void actionPerformed (ActionEvent e)
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 25

Lecture6Interfaces - Interfaces and Polymorphism Interfaces...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online