Posted by : Sudhir Chekuri Tuesday, 5 January 2016

  • Object is an instance of class.
  • Object will have memory.
  • Object is used to call methods of a class.
  • Object is a reference type.
  • To create this object "new" keyword is used.
Syntax

classname objectname= new constructor();

Example

maths m=new maths();

Example program using object for a class

Program

using System;

namespace Class_Example
{
    class Program
    {
        static void Main(string[] args)
        {
            maths m = new maths();
            m.add();
            Console.ReadKey();
        }
    }
    class maths
    {
        public void add()
        {
            int a = 10;
            int b = 20;
            Console.WriteLine("Sum is: " + (a + b));
        }
    }
}

Output

sum is : 30

Leave a Reply

Subscribe to Posts | Subscribe to Comments

Followers

Total Pageviews

Powered by Blogger.

- Copyright © 2013 DevStudent - Metrominimalist - Powered by Blogger - Designed by Johanes Djogan -