Monday, August 21, 2017

Interface

Interface class use for multiple class inheritance. When all the feature is to be implemented differently for all object then we go for an interface.We can't declare constructor or destructor inside an Interface class.Interface only declaration, not implementation.If a class inherit interface class, there need to be implemented otherwise compile error

Feature:

• Interface only have constant, not instant variable.
• Interface method always public or abstract.
• Interface class can’t be declared following modifiers private, protected, final or static.
• Interface class variable can’t be declared following modifiers private, protected, transient, volatile.
• Inside Interface class we can declare Instance and static block.Otherwise, compile error.


Example:

namespace IApplication
{
    public interface IT
    {
        void showValue();
    }

    public class T : IT
    {
        private string Code;
        private string date;

        public T(string c, string d)
        {
            Code = c;
            date = d;
        }

        public void showValue()
        {
            Console.WriteLine("{0}", Code);
            Console.WriteLine("{0}", date);
        }
    }
    class Tester
    {
        static void Main(string[] args)
        {
            T t1 = new T("4", "26/2017");
            t1.showValue();
            Console.ReadKey();
        }
    }


}

No comments:

Post a Comment