InterView Programming


1- what is the output of below Programme?   

class a
    {
        public void test()

        { Console.WriteLine("Class A"); }
    }

    class b:a
    {
        //public void test()

        //{ Console.WriteLine("Class B"); }
    }

    class c:b
    {
        public void test()

        { Console.WriteLine("Class C"); }
    }

    class Program
    {
        static void Main(string[] args)
        {
            a _a = new a();
            b _b = new b();
            c _c = new c();
            _a.test();
            _b.test();
            _c.test();
      _a = new c();
      _a.test();
        }
    }

Output: 
Class A
Class A
Class C
Class A

2- what is the output of below Programme?  


class a
    {
        public virtual void test()
        { Console.WriteLine("Class A"); }
    }

    class b:a
    {
        public override void test()

        { Console.WriteLine("Class B"); }
    }

    class c:b
    {
        public override void test()
        { Console.WriteLine("Class C"); }
    }

    class Program
    {
        static void Main(string[] args)
        {
            a _a = new a();
            b _b = new b();
            c _c = new c();
            _a.test();
            _b.test();
            _c.test();
            Console.WriteLine("------------------");

            _a = new b();
            _a.test();
            _b = new c();
            _b.test();
            Console.Read();
        }
    }
    
 Output: 
Class A
Class B
Class C
------------------
Class B
Class C

3- what is the output of below Programme?  



class a
    {
        public void test()
        { Console.WriteLine("Class A"); }
    }

    class b:a
    {
        public new virtual void test()
        { Console.WriteLine("Class B"); }
    }

    class c:b
    {
        public override void test()
        { Console.WriteLine("Class C"); }
    }


    class Program
    {
        static void Main(string[] args)
        {
            a _a = new a();
            b _b = new b();
            c _c = new c();
            _a.test();

            _b.test();

            _c.test();

            Console.WriteLine("------------------");
            _a = new b();
            _a.test();
            _b = new c();
            _b.test();
            Console.Read();
        }
    }
    

 Output: 

Class A
Class B
Class C
------------------
Class A
Class C


Note
1.  The virtual keyword is used to modify a method, property, indexer, or event declared in the base class and allow it to be overridden in the derived class.
2.  The override keyword is used to extend or modify a virtual/abstract method, property, indexer, or event of base class into derived class.
3. The new keyword is used to hide a method, property, indexer, or event of base class into derived class.
  exp: see the output of         _a = new b();
                         _a.test();
   in 3rd Programme.

4-  
 
5- 
 Digital Clock

6- Enter your Full Name and Get First Name as Output



7- Convert Inch Value into Feet



8- Enter any Number and get Reverse Number as Output



9- Check Palindrome Number


10- Pyiramid Programme



11-  Convert Second Value in Hours and Minuts



12- Table


13- Swap two Numbers without using third Variable-
Int a= 10;int b= 20;
a= a+b;
b= a-b
a= a-b;
C.W.(“a= ”+a+” b=  ”+b) 


14-  class MyCapsule
    {
      private char myChar;
      public void MyCharFunc() { myChar = 'A'; Console.Write(myChar); }
    }

    class Program:MyCapsule
    {
        static void Main(string[] args)
        {
            MyCapsule o = new MyCapsule();
            o.MyCharFunc();
            Console.Read();
        }
    }

OutPut = A

class MyCapsule
    {
      private char myChar;
      public void MyCharFunc(char ch) {
          Console.Write(ch);
      }
    }

    class Program:MyCapsule
    {
        static void Main(string[] args)
        {
            MyCapsule o = new MyCapsule();
            o.MyCharFunc('A');
            Console.Read();
        }
    }

OutPut = A

    class MyCapsule
    {
        public static int i = 5;
        public void test()
        {
            i = i + 5;
            Console.WriteLine(i);
        }
    }

    class Program
    {
        static void Main()
        {
            MyCapsule var = new MyCapsule();
            var.test();
            MyCapsule var1 = new MyCapsule();
            var1.test();
            Console.ReadKey();
        }
    }

Output- 10
             15
Note: static variable shared the value of it among all instances of the class.


    public class A
    {
        public A()
        {
            Console.WriteLine("Class A");
        }
    }

    public class B :A
    {
        public B()
        {
            Console.WriteLine("Class B");
        }

        private int myVar;

        public int MyProperty
        {
            get {
                return myVar; }
            set {
                    A a = new A();
                    myVar = value; }
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            B b = new B(); //output
            b.MyProperty = 8; //output
            Console.Read();
        }
    }

Output- Class A
             Class B
             Class A


    public abstract class A
    {
        public virtual void test1()
        {
            Console.WriteLine("hell");
        }
    }

    public class B : A
    {
        public override void test1()
        {
            Console.WriteLine("Paradise");
        }
    }

   public class Program
    {
        static void Main(string[] args)
        {
            A a = new B();
            a.test1();
            Console.ReadKey();
        }
    }
Output- Paradise


15- a simple recursive function in c#


    class Program
    {
        static void RecuriveFunction(int x)
        {
            if (x > 10)  //Condition to stop recursion
                return//Exit out of function
            else
            {
                Console.WriteLine(x);
                RecuriveFunction(x + 1);  //Call myself
            }
        }
     
        static void Main()
        {
            RecuriveFunction(1);
            Console.ReadKey();
        }
    }
16- get the characters of a string variable(string str = "asdfretb") in alphabatically order with the character position by using DataTable.

for Ex.
string name= "adb"
it should display like :
a   1
b   3
d   2


public class Program
    {
       void print()
       {
           DataTable dt = new DataTable();
           dt.Columns.Add("Name",typeof(string));
           dt.Columns.Add("Position",typeof(int));
           string str = "asdfretb";
           int len = str.Length;
           for (int i = 0; i < len; i++)
           {
               DataRow dr = dt.NewRow();
               dr[0] = str.Substring(i, 1);
               dr[1] = i;
               dt.Rows.Add(dr);
           }
           foreach (DataRow _dr in dt.Select("", "NAME ASC"))
           {
               Console.WriteLine("\t" + _dr["Name"] +"\t"+ _dr[1]);
           }
       }
      
        static void Main(string[] args)
        {
            Program p = new Program();
            p.print();
            Console.ReadKey();
        }
    }

Output - 

17- Fibonacci number

public class Program
    {
       public void Print()
       {
           int a, b;
           a = b = 1;
           while (b <= 1000)
           {
               Console.WriteLine(b);
               b = a + b;
               a = b - a;
           }
       }
        static void Main(string[] args)
        {
            Program p = new Program();
            p.Print();
            Console.ReadKey();
        }
    }


Output: 

1
2
3
5
8
13
21
34
55
89
144
233
377
610
987

18- We know that Base class constructor called first. But if we creating object with parameters, and base class have both constructor default and parameterized, then which constructor of baseclass called first.

Ans: Base class default constructor called first.

19- Then what you can do that base class parameterized constructor call first.

Ans: We can use "Base" keyword


20-

0 comments:

Post a Comment

Topics

ADO .Net (2) Ajax (1) Angular Js (17) Angular2 (24) ASP .Net (14) Azure (1) Breeze.js (1) C# (49) CloudComputing (1) CMS (1) CSS (2) Design_Pattern (3) DI (3) Dotnet (21) Entity Framework (3) ExpressJS (4) Html (3) IIS (1) Javascript (6) Jquery (9) Lamda (3) Linq (11) Mongodb (1) MVC (48) NodeJS (7) RDLC (1) Report (1) Sql Server (29) SSIS (3) SSRS (2) UI (1) WCF (12) Web Api (10) Web Service (1) XMl (1)