(*Class A is implemented to test two features of cool 1st : Whether an instance of a class is passed to a function by value or by reference 2nd : While assigning an instance of a object to another instance of that object do both of the objects points to the same memory or a new memory is allocated for the instance of the object to which another object of same type is assigned *) class A { property : Int; --This constructer enables to create an instance of this object --with its property set to the given value init (a : Int) : SELF_TYPE { { property <- a; self; } }; --The variable property is returned get_property () : Int { property }; --This method is used to increment value of the variable property increment_property () :Int { { property <- property + 1 ; property; } }; };--end of class A class Main inherits IO { (*Below is declared some instances of types Int,String,A and again A respectively These variables will be passed to appropriate methods to test whether they are passed by reference,with which original value changes, or passed by value,with which original value remains.*) an_Int : Int ; str : String; instanceA : A ; instanceA2 : A; --Takes a variable of type Int and changes the value int_funct (a : Int) : Int { { a <- 5*a; a; } }; --Takes a variable of type String and changes the value of it str_funct (str : String) : String{ { str <- "another string"; str; } }; --Takes a variable of type A and changes one property of it so changes it obj_funct (inst_of_A : A) : A { { inst_of_A.increment_property(); inst_of_A; } }; main () : Int{ { an_Int <- 5; out_string("\nThe value of integer variable before: \n"); out_int(an_Int); --value 5 is assigned to the variable an_Int and printed out int_funct(an_Int); out_string("\nThe value of integer after passing it to a method in which its value is changed!:\n"); out_int (an_Int); --an_Int is passed to a method which tries to change its value --, then the value of an_Int is printed out to test if it remains the same str <- "a string"; out_string("\n----------------------------------------------\nThe value of string variable before: \n"); out_string(str); -- value "a string" is assigned to the variable str and printed out str_funct(str); out_string("\nThe value of string after passing it to a method in which its value is changed!:\n"); out_string(str); -- str is passed to a method which tries to update its value, then --str is displayed to test if it remains the same instanceA <- (new A).init(10); out_string("\n------------------------------------------------\nThe value of instace of class A's property before!:\n"); out_int(instanceA.get_property()); --an instance of A with property value of 10 is created and its property is printed out obj_funct(instanceA); out_string("\nThe value of instance of class A's property after passing it to a method in which its property is changed:\n"); out_int(instanceA.get_property()); out_string("\n--------------------------------------------------\n"); --instanceA is passed to a method which tries to update property of it then, --value of property of the instance is printed to test if it reamins the same instanceA <- (new A).init(15); out_string("The value of instance of class A's property before!:\n"); out_int(instanceA.get_property()); --An instance of A with initial property value of 15 is created and the value of property is displayed instanceA2 <- instanceA; out_string("\nThe value of property of another instance of class A to which the first instance is assigned:\n"); out_int(instanceA2.get_property()); --instanceA is assigned to another instance of A which is instanceA2 to understand --whether a new memory is allocated or a pointer is constructed for the second instance instanceA2.increment_property(); out_string("\nThe value of property of the second instance after changing it invoking the method from secnd instance!:\n"); out_int(instanceA2.get_property()); -- property of instanceA2 is changed and printed out out_string("\nThe value of property of first instance of A after changing the value of the property of the second instance:\n"); out_int(instanceA.get_property()); out_string("\n\n"); -- after changing the property of the 2nd instance property of first instance is printed out -- to test whether it remained the same or is the same as that of 2nd instance 1; --return 1 } }; };