Methods: Communicating with Objects

We communicate with objects using methods. Methods are executable code within each object, for which an interface has been established. Sometimes the interface is only for the object itself. Other times it is an interface accessible by other objects. This chapter discusses that topic in detail.

3.3 Constructor Methods

Constructor Invocation

A constructor method is invoked only as part of a new expression when an instance object is first created. Each of these is a valid invocation of a ate an object OneRowNim constructor:

Annotation 2020-03-23 220317

The following constructor invocations are invalid because there are no matching constructor definitions:

Annotation 2020-03-23 220411

In the first case, there is no constructor method that takes a String parameter, so there’s no matching constructor. In the second case, there is no constructor that takes three int arguments. In both cases, the Java compiler would complain that there is no constructor method that matches the invocation.

Annotation 2020-03-23 220516