C# General Flashcards
Which of the following can be used to define the member of a class externally?
a) :
b) ::
c) #
d) none
b) ::
Which of the following operator can be used to access the member function of a class?
a) :
b) ::
c) .
d) #
c) .
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
d) Akshay is in city new delhi
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.
c) create a reference obj of the class shape and an object of type shape on the heap.
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) 8