head first java chapter 8
TRANSCRIPT
Head First Java Chapter 8Tom Henricksen
Abstract Classabstract class Canine extends Animal {
public void roam() {}
}
Dog class extends Canine {
Abstract vs Concrete● Abstract
○ Canine canine = new Canine();
● Concrete
○ Dog dog = new Dog();
Abstract methods● No body
● Must override
public abstract void eat();
java.lang.Object● Extend Object
● Basic methods
● Can instantiate
○ Object o = new Object();
Object overuseArrayList<Object> list = new ArrayList<Object>();
list.add(dog);
Dog dog2 = list.get(0);
Method calls● Reference type
○ Dog dog = new Dog();
○ Object o = dog;
○ o.bark();
Use your methods● Object methods
● Polymorphism
○ Snowboard s = new Snowboar();
○ Object o = s;
Casting● Cast back
○ Dog d = (Dog)o;
○ d.bark();
● Instanceof
Interface● Similar to an abstract class
○ public interface Pet {...}
○ public Dog implements Pet {...}
Interface methods● No body
○ void play();
● Must implement
Invoking the Superclassvoid runReport() {
super.runReport();
}
Assignment
● Exercise 1
● Exercise 2
● Exercise 3
Interfaces
Interfaces
Interfaces
Super