Back to all rules
What this rule checks
Uses inheritance via extends
Code Examples
PASS — this code satisfies the rule
Ball small = new Ball(20);
Ball big = new Ball(60); // one class, a size field instead of a subclass
void setup() {
size(400, 400);
}
void draw() {
background(255);
small.show(100);
big.show(300);
}
class Ball {
float diameter;
Ball(float d) {
diameter = d;
}
void show(float x) {
ellipse(x, 200, diameter, diameter);
}
}
FAIL — this code triggers the rule
Ball small = new Ball();
BigBall big = new BigBall();
void setup() {
size(400, 400);
}
void draw() {
background(255);
small.show(100);
big.show(300);
}
class Ball {
float diameter = 20;
void show(float x) {
ellipse(x, 200, diameter, diameter);
}
}
class BigBall extends Ball { // inheritance with extends
BigBall() {
diameter = 60;
}
}
Overview
| Category |
Out of Scope
|
| Type |
Custom Zita
|
| Priority |
3 (1 = highest, 5 = lowest) |
| Status |
Active
|
PMD Configuration
| Java class |
nl.utwente.processing.pmd.rules.HasInheritanceRule |
| Message template |
Inheritance found using the 'extends' keyword |