Classes and Objects

Classes:

  • Type defines by user
  • Template to create objects
  • Made by:

– Instanced fields or attributes = data

– Procedures and functions = Methods

Name and sound are datas, and getName is a method

Object:

-Principal characteristics

  • Identity. It is the characteristic that allows to differentiate an object of other.
  • State. The state of an object is determined by a series of parameters or these.
  • Behavior. They are the actions that can be carried out on the object. In other words, it is the methods or procedures that performs the object.

-Use of object:

When we create an object from a class, it is said that we have created an instance of the class”. Class Pet object Toby o Any instantiated object of a class contains a copy of all the attributes defined in the class.

-Declare an object:

To create an object follow the next steps:

Declaration: Declare the object type

  • Instantiation: Creation of object with the operator new