C# General Flashcards

1
Q

Which of the following can be used to define the member of a class externally?

a) :
b) ::
c) #
d) none

A

b) ::

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Which of the following operator can be used to access the member function of a class?

a) :
b) ::
c) .
d) #

A

c) .

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
using System;
class emp
  {
      public string name;
      public string address;
      public void display()
      {
          Console.WriteLine("{0} is in city {1}", name, address);
      }
  }
  class Program
  {
      static void Main(string[] args)
      {
          emp obj = new emp();
          obj.name = "Akshay";
          obj.address = "new delhi";
          obj.display();
          Console.ReadLine();
      }
  }

a) Syntax error
b) {0} is in city {1} Akshay new delhi
c) Akshay is in new delhi
d) Akshay is in city new delhi
e) executes successfully and prints nothing

A

d) Akshay is in city new delhi

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Which of the following statements are correct for the given code snippet:
shape obj;
obj = new shape();

a) creates an object of class shape.
b) To create an object of type shape on the heap or stack depending on its size.
c) create a reference obj of the class shape and an object of type shape on the heap.
d) create an object of type shape on the stack.

A

c) create a reference obj of the class shape and an object of type shape on the heap.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
What will be the output of the following code snippet?
using System;
class program
{
    static void Main(string[] args)
    {
        int num = 2;
        fun1 (ref num);
        Console.WriteLine(num);
        Console.ReadLine();
    }
    static void fun1(ref int num)
    {
        num = num * num * num;
    }
}

a) 8
b) 0
c) 2
d) 16

A

a) 8

How well did you know this?
1
Not at all
2
3
4
5
Perfectly