Enter your email address:

    Delivered by FeedBurner

Polymorphism Java


Abstract Classes
• May Contain abstract methods
• Some methods and data may be defined
abstract class ColouredShape {
private Colour c; // storage allocated for each
public abstract void draw();
public Colour getColour() {
return c;
}
public abstract void erase();
}
• No instances allowed
• Subclasses must implement all abstract methods or they are also abstract

Interface
• Contains no implementation
• Method signatures + static final data members
Method signature =
return type + method name + argument lis
• Establishes a protocol
• Public or friendly
interface Shape {
Point zero = Point(0,0);
// Cannot have method implementations:
void erase();
void draw();
}

Interfaces and Classes
• A class may implement one or more interfaces
class Circle implements Shape {
pivate int radius;
public void erase() {
...
}
public String draw() {
...
}
public int getRadius(){
...
}
}
• An interface may extend one or more other interface

Abstract Classes
• May Contain abstract methods
• Some methods and data may be defined
abstract class ColouredShape {
private Colour c; // storage allocated for each
public abstract void draw();
public Colour getColour() {
return c;
}
public abstract void erase();
}
• No instances allowed
• Subclasses must implement all abstract methods or they are also abstract

Interface
• Contains no implementation
• Method signatures + static final data members
Method signature =
return type + method name + argument lis
• Establishes a protocol
• Public or friendly
interface Shape {
Point zero = Point(0,0);
// Cannot have method implementations:
void erase();
void draw();
}

Interfaces and Classes
• A class may implement one or more interfaces
class Circle implements Shape {
pivate int radius;
public void erase() {
...
}
public String draw() {
...
}
public int getRadius(){
...
}
}
• An interface may extend one or more other interface

Recent Articles

Blog Archive