









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!










Department of Computer Science — University of San Francisco – p.1/
Inheritance review
Department of Computer Science — University of San Francisco – p.2/
16-2:^ Example
public^
class^ Professor
extends
Person
String officeNum; public^ void^ teach()
public^ void^ grade()
public^ void^ forget()
Department of Computer Science — University of San Francisco – p.4/
Constructors and Inheritance
Person(String
lname)
lastName
=^ lname;
Department of Computer Science — University of San Francisco – p.5/
Constructors and Inheritance
Professor(String
lname,
String office)
super(lname);officeNum
=^ office;
Department of Computer Science — University of San Francisco – p.7/
More on super()
public^
void^ greet()
System.out.println(‘‘Nice
to^ meet
you’’);
Department of Computer Science — University of San Francisco – p.8/
Exercise
Department of Computer Science — University of San Francisco – p.10/
Interfaces
Department of Computer Science — University of San Francisco – p.11/
Interfaces
Department of Computer Science — University of San Francisco – p.13/
Interfaces in the JDK
Department of Computer Science — University of San Francisco – p.14/
Comparable
public^
class^ Cat
extends
Animal implements
Comparable
public^ int^ compareTo(Object
other)
if^ (!(other
instanceof
Cat))^
System.out.println("Can’t
compare
these!");
return^
((Cat)other).age; if^ (age
<^ age2) return^
-1;else^ if^ (age
^ age2) return^
1;else return^
Department of Computer Science — University of San Francisco – p.16/
Exercise
Department of Computer Science — University of San Francisco – p.17/