Constructor (object-oriented Programming) - Constructors Simplified, With Pseudocode

Constructors Simplified, With Pseudocode

Constructors are always part of the implementation of classes. A class (in programming) refers to a specification of the general traits of the set of objects that are members of the class rather than the specific traits of any object at all. A simple analogy in pseudocode follows. Consider the set (or class, using its generic meaning) of students at some school. Thus we have

class Student { // refers to the class of students // ... more omitted ... }

However, the class Student just provides a generic prototype of what a student should be. To use it, the programmer creates each student as an object or instance of the class. This object is a real quantity of data in memory whose size, layout, traits, and (to some extent) behavior are determined by the class definition. The usual way of creating objects is to call a constructor (classes may in general have many independent constructors). For example,

class Student { Student (String studentName, String Address, int ID) { // ... storage of input data and other internal fields here ... } // ... }

Read more about this topic:  Constructor (object-oriented Programming)