NumberedCircle Class

We can create another kind of circle: a numbered circle that behaves like a circle, but displays a unique number on each circle.

NumberedCircle Class

We can create another kind of circle: a numbered circle that behaves like a circle, but displays a unique number on each circle.

NumberedCircle Class

We can create another kind of circle: a numbered circle that behaves like a circle, but displays a unique number on each circle.

NumberedCircle Class

To do this, display the number just before drawing the circle itself. We use the x and y variables that we want to inherit from the Circle superclass. This means that x and y are no longer private to the Circle class, but they must be protected instead.

NumberedCircle Class

To do this, display the number just before drawing the circle itself. We use the x and y variables that we want to inherit from the Circle superclass. This means that x and y are no longer private to the Circle class, but they must be protected instead.

NumberedCircle Class

To do this, display the number just before drawing the circle itself. We use the x and y variables that we want to inherit from the Circle superclass. This means that x and y are no longer private to the Circle class, but they must be protected instead.

NumberedCircle Class

This mynumber variable is an extra piece of state to add to the new subclass.

NumberedCircle Class

This mynumber variable is an extra piece of state to add to the new subclass.

NumberedCircle Class

This mynumber variable is an extra piece of state to add to the new subclass.

NumberedCircle Class

Its value must be set when the new NumberedCircle is initialised, in the constructor.

NumberedCircle Class

Its value must be set when the new NumberedCircle is initialised, in the constructor.

NumberedCircle Class

Its value must be set when the new NumberedCircle is initialised, in the constructor.

NumberedCircle Class

But what value should it be given? We ned a value that is 1 for the first circle, 2 for the second and so on. We can declare a class variable that is incremented each time a new NumberedCircle is created.

NumberedCircle Class

But what value should it be given? We ned a value that is 1 for the first circle, 2 for the second and so on. We can declare a class variable that is incremented each time a new NumberedCircle is created.

NumberedCircle Class

But what value should it be given? We ned a value that is 1 for the first circle, 2 for the second and so on. We can declare a class variable that is incremented each time a new NumberedCircle is created.

NumberedCircle Class

But what value should it be given? We ned a value that is 1 for the first circle, 2 for the second and so on. We can declare a class variable that is incremented each time a new NumberedCircle is created.

NumberedCircle Class

But what value should it be given? We ned a value that is 1 for the first circle, 2 for the second and so on. We can declare a class variable that is incremented each time a new NumberedCircle is created.

NumberedCircle Class

But hang on, a new NumberedCircle gets initialised as far as numbering is concerned, but how about the more fundamental Circle construction? Our new constructor must invoke the existing superclass constructor as follows:

NumberedCircle Class

But hang on, a new NumberedCircle gets initialised as far as numbering is concerned, but how about the more fundamental Circle construction? Our new constructor must invoke the existing superclass constructor as follows:

NumberedCircle Class

But hang on, a new NumberedCircle gets initialised as far as numbering is concerned, but how about the more fundamental Circle construction? Our new constructor must invoke the existing superclass constructor as follows:

NumberedCircle Class

Finished code.

class RedCircle extends Circle {

public void draw(java.awt.Graphics g){
	g.setColor(java.awt.Color.red);
	super.draw(g);
	}

}
class RedCircle extends Circle {

public void draw(java.awt.Graphics g){
	g.setColor(java.awt.Color.red);
	super.draw(g);
	}

}
class NumberedCircle extends Circle {

public void draw(java.awt.Graphics g){
	g.setColor(java.awt.Color.red);
	super.draw(g);
	}

}
class NumberedCircle extends Circle {

public void draw(java.awt.Graphics g){
	g.setColor(java.awt.Color.red);
	super.draw(g);
	}

}
class NumberedCircle extends Circle {

public void draw(java.awt.Graphics g){
	g.setColor(java.awt.Color.red);
	super.draw(g);
	}

}
class NumberedCircle extends Circle {

public void draw(java.awt.Graphics g){
	g.drawString("Number "+mynumber, x+10, y);
	super.draw(g);
	}

}
class NumberedCircle extends Circle {

public void draw(java.awt.Graphics g){
	g.drawString("Number "+mynumber, x+10, y);
	super.draw(g);
	}

}
class NumberedCircle extends Circle {

*public void draw(java.awt.Graphics g){
	g.drawString("Number "+mynumber, x+10, y);
	super.draw(g);
	}

}
class NumberedCircle extends Circle {

int mynumber;

public void draw(java.awt.Graphics g){
	g.drawString("Number "+mynumber, x+10, y);
	super.draw(g);
	}

}
class NumberedCircle extends Circle {

int mynumber;

public void draw(java.awt.Graphics g){
	g.drawString("Number "+mynumber, x+10, y);
	super.draw(g);
	}

}
class NumberedCircle extends Circle {

int mynumber;

*public void draw(java.awt.Graphics g){
	g.drawString("Number "+mynumber, x+10, y);
	super.draw(g);
	}

}
class NumberedCircle extends Circle {

int mynumber;

public NumberedCircle(){
	mynumber=???;
	}

public void draw(java.awt.Graphics g){
	g.drawString("Number "+mynumber, x+10, y);
	super.draw(g);
	}

}
class NumberedCircle extends Circle {

int mynumber;

public NumberedCircle(){
	mynumber=???;
	}

public void draw(java.awt.Graphics g){
	g.drawString("Number "+mynumber, x+10, y);
	super.draw(g);
	}

}
class NumberedCircle extends Circle {

int mynumber;

public NumberedCircle(){
	mynumber=???;
	}

public void draw(java.awt.Graphics g){
	g.drawString("Number "+mynumber, x+10, y);
	super.draw(g);
	}

}
class NumberedCircle extends Circle {

int mynumber;

public NumberedCircle(){
	mynumber=nthCircle++;
	}

public void draw(java.awt.Graphics g){
	g.drawString("Number "+mynumber, x+10, y);
	super.draw(g);
	}

}
class NumberedCircle extends Circle {

int mynumber;

*public NumberedCircle(){
	mynumber=nthCircle++;
	}

public void draw(java.awt.Graphics g){
	g.drawString("Number "+mynumber, x+10, y);
	super.draw(g);
	}

}
class NumberedCircle extends Circle {

int mynumber;

static int nthCircle=1;

public NumberedCircle(){
	mynumber=nthCircle++;
	}

public void draw(java.awt.Graphics g){
	g.drawString("Number "+mynumber, x+10, y);
	super.draw(g);
	}

}
class NumberedCircle extends Circle {

int mynumber;

static int nthCircle=1;

public NumberedCircle(){
	mynumber=nthCircle++;
	}

public void draw(java.awt.Graphics g){
	g.drawString("Number "+mynumber, x+10, y);
	super.draw(g);
	}

}
class NumberedCircle extends Circle {

int mynumber;

static int nthCircle=1;

public NumberedCircle(){
	*mynumber=nthCircle++;
	}

public void draw(java.awt.Graphics g){
	g.drawString("Number "+mynumber, x+10, y);
	super.draw(g);
	}

}
class NumberedCircle extends Circle {

int mynumber;

static int nthCircle=1;

public NumberedCircle(){
	super();
	mynumber=nthCircle++;
	}

public void draw(java.awt.Graphics g){
	g.drawString("Number "+mynumber, x+10, y);
	super.draw(g);
	}

}
class NumberedCircle extends Circle {

int mynumber;

static int nthCircle=1;

public NumberedCircle(){
	super();
	mynumber=nthCircle++;
	}

public void draw(java.awt.Graphics g){
	g.drawString("Number "+mynumber, x+10, y);
	super.draw(g);
	}

}