Professional Documents
Culture Documents
Software Development
(c) Aaron Kans
Hit
START
Hit
START
Learning Objectives
Circle Triangle
draw() draw()
3DCircle
is aiskind
CircleObject a kind of Shape
of Shape
type
Circle c1 = new Circle ( );
Shape
Circle
3DCircle
Objectis a kind of Circle
type
3DCircle Shape c3d = new 3DCircle ( );
Circle
3DCircle
draw()
SomeClass
draw()
In Java you
cannot inherit
SomeClass from more than 1
class
SomeClass
draw()
SomeClass
SomeClass
An interface
is like a
contract
SomeClass
SomeClass
SomeClass
SomeClass
SomeClass
SomeClass
Oblong
length: double
height: double
// methods
Oblong
length: double
height: double
// methods
check(): boolean
(c) Aaron Kans
public class Oblong
{
private double length;
private double height;
}
(c) Aaron Kans
public class Oblong
{
private double length;
private double height;
}
(c) Aaron Kans
public class Oblong implements Checkable
{
private double length;
private double height;
}
(c) Aaron Kans
<<interface>>
Checkable
check(): boolean
Robot
xValue: int
yValue: int
// methods
Robot
xValue: int
yValue: int
// methods
check(): boolean
(c) Aaron Kans
TestingApp…
}
}
} (c) Aaron Kans
public class TestingApp
{
public static void main(String[ ] args)
{
// create objects to test here and send to testObject
}
}
}
} (c) Aaron Kans
public class TestingApp
{
public static void main(String[ ] args)
{
// create objects to test here and send to testObject
}
if(mouseDown)
{
g.drawString("Keep trying!!!", width/2 - 40, height -10);
}
}
}
}
(c) Aaron Kans
It’s a bit annoying to
have to write dummy
methods to meet an
interface. Is there an
easier way?
We have to
provide code for 5
methods above.
SomeClass
This class
implements
MouseListener by
providing 5 dummy
methods. MouseAdapter
MouseAdapter
No we just inherit
from the adapter
and override the
methods we need
SomeClass
to.
mousePressed
mouseReleased
(c) Aaron Kans
public class MouseAdapter implements MouseListener
{
public void mousePressed(MouseEvent e)
{
}
public void mouseReleased(MouseEvent e)
{
}
public void mouseClicked(MouseEvent e)
{
}
public void mouseEntered(MouseEvent e)
{
}
public void mouseExited(MouseEvent e)
{
}
}
(c) Aaron Kans
Just before we finish….
BankAccount
}
}
}
}
BankAccount
toString(): String
RUN
(c) Aaron Kans
Account Number: 001
Account Name: Sarah Patel
Current Balance: 0.0
RUN
(c) Aaron Kans
(c) Aaron Kans