

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A portion of a university textbook on programming ii, focusing on interfaces and inheritance. It covers concepts such as inheritance, constructors, and superclass methods, as well as the introduction of interfaces and their implementation. Students will learn how to create classes that extend other classes and implement interfaces, and how to use super() to call parent class constructors and methods.
Typology: Study notes
1 / 3
This page cannot be seen from the preview
Don't miss anything!


Chris Brooks
Department of Computer Science
University of San Francisco
Department of Computer Science — University of San Francisco – p. 1/
??
-^
-^
-^
-^
Department of Computer Science — University of San Francisco – p. 2/
??
public
class
Person
public
String
lastName;
public
String
id;
public
void
eat()
public
void
sleep()
Department of Computer Science — University of San Fra
public
class
Professor
extends
Person
public
String
officeNum;
public
void
teach()
public
void
grade()
public
void
forget()
Department of Computer Science — University of San Francisco – p. 4/
??
-^
Person(String
lname)
lastName
= lname;
-^
Department of Computer Science — University of San Francisco – p. 5/
??
-^
Professor(String
lname,
String
office)
lastName
lname;
officeNum
= office;
-^
Department of Computer Science — University of San Fra
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()
-^
-^
-^
in
Person.java
public
void
greet()
System.out.println(‘‘Nice
to
meet
you’’);
Department of Computer Science — University of San Francisco – p. 8/
??
More on super()
-^
in
Professor.java
public
void
greet()
System.out.print(‘‘I
do
say,
old
chap,’’);
super.greet(); }
Department of Computer Science — University of San Fra
Exercise
-^
-^
-^
-^
-^
Department of Computer Science — University of San Francisco – p. 10/
??
Interfaces
-^
-^
-^
-^
-^
-^
Department of Computer Science — University of San Francisco – p. 11/
??
Interfaces
-^
-^
interface
FlyingThing
public
void
fly();
} public
class
Bat
extends
Animal
implements
FlyingThing
public
void
fly()
System.out.println(‘‘I’m
flying!’’);
Department of Computer Science — University of San Fran