Abstract method
- no body, declaration ends with a semicolon
- implemented in the first concrete subclass in the inheritance tree
Casting
-Reference variable of type Object can’t be assigned to any other reference type without a cast
-A cast can be used to assign a reference variable of one type to reference variable of a subtype,
but at runtime the cast will fail if the object on the heap is NOT of a type compatible with the cast
Inheritance
- Multiple inheritance is not allowed in Java ==> Deadly Diamond of Death
Interface
- a pure abstract class
- A class can implement multiple interfaces
- All interface methods are implicitly public and abstract ==> a class that implements an interface must implement ALL the methods of the interface
Super
-invoke superclass version of a method from a subclass–> use super keyword
GUI
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
listener interface
- bridge between listener(you) and event source(button)
e.g. ItemListener interface for JCheckbox, void itemStateChanged(ItemEvent event)
KeyListener interface
Implementation of listeners
- 1. class needs to implement listener interface
e.g. public class abc implements ActionListener
- 2. register the listener to the component
e.g. button.addActionListner(this);
- 3. implements the details of event method
e.g. public void actionPerformed(ActionEvent event){…}
multiple listeners issue ==> inner class
call repaint() –> invoke paintComponent(Graphics g)