Introduction to OOP Chapter 5: Messages Instances and Initialization: next previous audio real text


A constructor is a function that is implicitly invoked when a new object is created. The constructor performs whatever actions are necessary in order to initialize the object.

class PlayingCard {	// a Java constructor
	public PlayingCard (int s, int r) {
		suit = s;
		rank = r;
		faceUp = true;

Intro OOP, Chapter 5, Slide 10