To create classes and object in ns2
no vote
An OTcl script that defines two object classes, "teacher" and "student", where "Student" is the child class of "teacher", and a member function called "greet" for each class. After the class definitions, each object instance is declared, the "subject" variable of each instance is set to maths for teacher and name for student and the "greet" member function of each object instance is called. The keyword Class is to create an object class and instproc is to define a member function to an object class. Class inheritance is specified using the keyword -superclass. In defining member functions, $self acts same as the "this" pointer in C++, and instvar checks if the following variable name is already declared in its class or in its superclass. Finally, to create an object instance, the keyword new is used.