Thursday, 25 August 2011

Message Passing in Object Oriented Programming


              Message passing is a method by which an object sends data to another object or requests other object to invoke method. This is also known as interfacing. It acts like a messenger from one object to other object to convey specific instructions.

The following Program explains about the message passing...




class Base
    {
        public Base()
        { }
        public Base(string s)
        {
            Console.WriteLine("hi " +s);
        }
    }
    class Derived : Base
    {
       
        public Derived(string s)
        {
            Base b = new Base(s);
            Console.WriteLine(s);
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Derived d = new Derived("Krishna");
            Console.ReadLine();
        }
    }

Output:

hi Krishna
Krishna

// Here Object d invokes the Constructor of base class that means object interaction will be takes place between Object d and Object b.


No comments:

Post a Comment