C Sample Test,Sample questions

Question:
 
Which of the following statements are correct about static functions?

1. Static functions are invoked using objects of a class.

2.Static functions can access static data as well as instance data.

3.Static functions are outside the class scope.

4.Static functions are invoked using class.

Posted Date:-2021-02-24 04:05:30


Question:
  
Which of the following statements is correct about constructors in C#.NET?

1.A constructor cannot be declared as private.

2. A constructor cannot be overloaded.

3.A constructor can be a static constructor.

4.A constructor cannot access static data.

Posted Date:-2021-02-24 04:05:30


Question:
  
Which of the following statements is correct?

1.There is one garbage collector per program running in memory.

2.There is one common garbage collector for all programs.

3.An object is destroyed by the garbage collector when only one reference refers to it.

4.We have to specifically run the garbage collector after executing Visual Studio.NET.

Posted Date:-2021-02-24 04:05:30


Question:
How many times can a constructor be called during lifetime of the object?

1.As many times as we call it.

2. Only once.

3.Depends upon a Project Setting made in Visual Studio.NET.

4.Any number of times before the object gets garbage collected.

Posted Date:-2021-02-24 04:05:30


Question:
In which of the following should the methods of a class differ if they are to be treated as overloaded methods?

Type of arguments
Return type of methods
Number of arguments
Names of methods
Order of arguments

1.2, 4

2.3, 5

3.1, 3, 5

4.3, 4, 5

Posted Date:-2021-02-24 04:05:30


Question:
Which of the following statements is correct?

1. A constructor can be used to set default values and limit instantiation.

2.C# provides a copy constructor.

3.Destructors are used with classes as well as structures.

4.A class can have more than one destructor.

Posted Date:-2021-02-24 04:05:30


Question:
What will be the output of the C#.NET code snippet given below?

namespace IndiabixConsoleApplication
{
    class Sample
    { 
        public static void fun1()
        { 
            Console.WriteLine("Bix1 method");
        }
        public void fun2()
        { 
            fun1(); 
            Console.WriteLine("Bix2 method");
        }
        public void fun2(int i)
        { 
            Console.WriteLine(i);
            fun2(); 
        } 
    } 
    class MyProgram
    { 
        static void Main(string[ ] args)
        { 
            Sample s = new Sample(); 
            Sample.fun1(); 
            s.fun2(123);
        } 
    } 
}

1.Bix1 method 123 Bixl method Bix2 method

2.Bix1 method 123 Bix2 method

3.Bix2 method 123 Bix2 method Bixl method

4.Bixl method 123

Posted Date:-2021-02-24 04:05:30


Question:
What will be the output of the C#.NET code snippet given below?

namespace IndiabixConsoleApplication
{ 
    class Sample
    { 
        static Sample()
        { 
            Console.Write("Sample class ");
        }
        public static void Bix1()
        { 
            Console.Write("Bix1 method ");
        } 
    } 
    class MyProgram
    { 
        static void Main(string[ ] args)
        { 
            Sample.Bix1();
        } 
    } 
}

1.Sample class Bix1 method

2.Bix1 method

3.Sample class

4.Bix1 method Sample class

Posted Date:-2021-02-24 04:05:30


Question:
Which of the following statements are correct about constructors in C#.NET?

Constructors cannot be overloaded.
Constructors always have the name same as the name of the class.
Constructors are never called explicitly.
Constructors never return any value.
Constructors allocate space for the object in memory.

1.1, 3, 5

2.2, 3, 4

3.. 3, 5

4.. 4, 5

Posted Date:-2021-02-24 04:05:30


Question:
Which of the following statements are correct about static functions?

Static functions can access only static data.
Static functions cannot call instance functions.
It is necessary to initialize static data.
Instance functions can call static functions and access static data.
this reference is passed to static functions.

1.1, 2, 4

2.2, 3, 5

3.3, 4

4.4, 5

Posted Date:-2021-02-24 04:05:30


Question:
Which of the following statements are correct about the C#.NET code snippet given below?

class Sample
{
    static int i;
    int j;
    public void proc1()
    {
        i = 11; 
        j = 22;
    }
    public static void proc2()
    {
        i = 1;
        j = 2;
    }
    static Sample()
    {
        i = 0; 
        j = 0;
    }
}

1. i cannot be initialized in proc1().

2.proc1() can initialize i as well as j.

3. j can be initialized in proc2().

4.The constructor can never be declared as static.

Posted Date:-2021-02-24 04:05:30


Question:
Which of the following statements is correct about constructors?

1.If we provide a one-argument constructor then the compiler still provides a zero-argument constructor.

2.Static constructors can use optional arguments.

3.Overloaded constructors cannot use optional arguments.

4.If we do not provide a constructor, then the compiler provides a zero-argument constructor.

Posted Date:-2021-02-24 04:05:30


Question:
Which of the following statements is correct about the C#.NET code snippet given below?

namespace IndiabixConsoleApplication
{ 
    class Sample
    { 
        public int func()
        {
            return 1;
        } 
        public Single func()
        { 
            return 2.4f ;
        } 
    } 
    class Program
    { 
        static void Main(string[ ] args)
        {
            Sample s1 = new Sample(); 
            int i;
            i = s1.func(); 
            Single j; 
            j = s1.func(); 
        } 
    } 
}

1.func() is a valid overloaded function.

2. Overloading works only in case of subroutines and not in case of functions.

3.func() cannot be considered overloaded because: return value cannot be used to distinguish between two overloaded functions.

4. The call to i = s1.func() will assign 1 to i.

Posted Date:-2021-02-24 04:05:30


Question:
Which of the following ways to create an object of the Sample class given below will work correctly?

class Sample
{
    int i;
    Single j;
    double k;
    public Sample (int ii, Single jj, double kk)
    {
        i = ii;
        j = jj;
        k = kk;
    } 
}

1.Sample s1 = new Sample();

2.Sample s1 = new Sample(10);

3.Sample s2 = new Sample(10, 1.2f);

4.Sample s3 = new Sample(10, 1.2f, 2.4);

Posted Date:-2021-02-24 04:05:30


More MCQS

  1. C# MCQS -Programming (.NET Framework)
  2. C# MCQS -Programming(Control Instructions)
  3. C# MCQS - Functions and Subroutines(.NET Framework)
  4. C# Programming-Constructors
  5. C# Programming- Arrays
  6. C# Programming -Structures
  7. C# Programming-Properties
  8. C# Programming -Exception Handling
  9. C# Programming -Interfaces
  10. C# Programming -Delegates
  11. C# Programming -Generics
  12. C# Programming - Datatypes
  13. C# Programming- Operators
  14. C# Programming -Classes and Objects
Search
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!