logo

CuriousTab

CuriousTab

Discussion


Home C# Programming Interfaces See What Others Are Saying!
  • Question
  • Which of the following is the correct way to implement the interface given below?

    interface IPerson
    { 
        String FirstName
        {
            get;
            set; 
        } 
    }


  • Options
  • A.
    class Employee : IPerson
    {
        private String str; 
        public String FirstName
        {
            get
            { 
                return str;
            } 
            set
            { 
                str = value;
            } 
        } 
    }
  • B.
    class Employee
    {
        private String str;
        public String IPerson.FirstName
        { 
            get
            { 
                return str;
            } 
            set
            { 
                str = value;
            } 
        } 
    }
  • C.
    class Employee : implements IPerson
    {
        private String str; 
        public String FirstName
        { 
            get
            { 
                return str;
            } 
            set
            {
                str = value; 
            } 
        } 
    }
  • D. None of the above

  • Correct Answer
  • class Employee : IPerson
    {
        private String str; 
        public String FirstName
        {
            get
            { 
                return str;
            } 
            set
            { 
                str = value;
            } 
        } 
    }
     


  • More questions

    • 1. An Account class has a property called accountNo and acc is a reference to a bank object and we want the C#.NET code snippet given below to work. Which of the following options will ensure this functionality?

      acc.accountNo = 10; 
      Console.WriteLine(acc.accountNo);

    • Options
    • A. Declare accountNo property with both get and set accessors.
    • B. Declare accountNo property with only get accessor.
    • C. Declare accountNo property with get, set and normal accessors.
    • D. Declare accountNo property with only set accessor.
    • E. None of the above
    • Discuss
    • 2. Which of the following statements is correct about an interface?

    • Options
    • A. One interface can be implemented in another interface.
    • B. An interface can be implemented by multiple classes in the same program.
    • C. A class that implements an interface can explicitly implement members of that interface.
    • D. The functions declared in an interface have a body.
    • Discuss
    • 3. Which of the following statements is correct about the C#.NET code snippet given below?

      class Trial
      { 
          int i;
          Decimal d;
      }
      struct Sample
      {
          private int x;
          private Single y;
          private Trial z;
      }
      Sample ss = new Sample();

    • Options
    • A. ss will be created on the heap.
    • B. Trial object referred by z will be created on the stack.
    • C. z will be created on the heap.
    • D. Both ss and z will be created on the heap.
    • E. ss will be created on the stack.
    • Discuss
    • 4. Which of the following snippets are the correct way to convert a Single into a String?

      1. Single f = 9.8f; 
        String s;
        s = (String) (f);
      2. Single f = 9.8f; 
        String s;
        s = Convert.ToString(f);
      3. Single f = 9.8f; 
        String s;
        s = f.ToString();
      4. Single f = 9.8f; 
        String s;
        s = Clnt(f);
      5. Single f = 9.8f; 
        String s;
        s = CString(f);

    • Options
    • A. 1, 2
    • B. 2, 3
    • C. 1, 3, 5
    • D. 2, 4
    • Discuss
    • 5. What will be the output of the C#.NET code snippet given below?

      int num = 1, z = 5;
      
      if (!(num <= 0))
          Console.WriteLine( ++num + z++ + " " + ++z ); 
      else
          Console.WriteLine( --num + z-- + " " + --z ); 

    • Options
    • A. 5 6
    • B. 6 5
    • C. 6 6
    • D. 7 7
    • Discuss
    • 6. Which of the following statements is correct?

    • Options
    • A. When used as a modifier, the new keyword explicitly hides a member inherited from a base class.
    • B. Operator overloading works in different ways for structures and classes.
    • C. It is not necessary that all operator overloads are static methods of the class.
    • D. The cast operator can be overloaded.
    • Discuss
    • 7. Which of the following is the correct ways to set a value 3.14 in a variable pi such that it cannot be modified?

    • Options
    • A. float pi = 3.14F;
    • B. #define pi 3.14F;
    • C. const float pi = 3.14F;
    • D. const float pi; pi = 3.14F;
    • E. pi = 3.14F;
    • Discuss
    • 8. Which of the following statements is correct about the C#.NET program given below if a value "ABCD" is input to it?

      using System;
      namespace CuriousTabConsoleApplication
      {
          class MyProgram
          {
              static void Main(string[] args)
              {
                  int index; 
                  int vat = 88;
                  int[] a = new int(5];
                  try
                  {
                      Console.Write("Enter a number: ");
                      index = Convert.Toint32(Console.ReadLine());
                      a[index] = val;
                  }
                  catch(Exception e)
                  {
                      Console.Write("Exception occurred");
                  }
                  Console.Write("Remaining program");
              }
          }
      }

    • Options
    • A. It will output: Exception occurred
    • B. It will output: Remaining program
    • C. It will output: Remaining program Exception occurred
    • D. It will output: Exception occurred Remaining program
    • E. The value 88 will get assigned to a[0].
    • Discuss
    • 9. Which statement will you add in the function fun() of class B, if it is to produce the output "Welcome to CuriousTab.com!"?

      namespace CuriousTabConsoleApplication
      { 
          class A
          {
              public void fun()
              {
                  Console.Write("Welcome");
              } 
          } 
          class B: A
          {
              public void fun()
              {
                  // [*** Add statement here ***]
                  Console.WriteLine(" to CuriousTab.com!");
              } 
          } 
          class MyProgram
          { 
              static void Main (string[ ] args)
              { 
                  B b = new B(); 
                  b.fun();
              } 
          } 
      }

    • Options
    • A. base.fun();
    • B. A::fun();
    • C. fun();
    • D. mybase.fun();
    • E. A.fun();
    • Discuss
    • 10. Which of the following statements are correct about data types?

      1. If the integer literal exceeds the range of byte, a compilation error will occur.
      2. We cannot implicitly convert non-literal numeric types of larger storage size to byte.
      3. Byte cannot be implicitly converted to float.
      4. A char can be implicitly converted to only int data type.
      5. We can cast the integral character codes.

    • Options
    • A. 1, 3, 5
    • B. 2, 4
    • C. 3, 5
    • D. 1, 2, 5
    • Discuss


    Comments

    There are no comments.

Enter a new Comment