Home / C# Programming / Constructors :: General Questions

C# Programming :: Constructors

  1. Is it possible to invoke Garbage Collector explicitly?

  2. A.
    Yes
    B.
    No

    View Answer

    Workspace

    Discuss Discuss in Forum


  3. 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;   
        } 
    
    }   
    

     

  4. A.

    i cannot be initialized in proc1().

    B.

    proc1() can initialize i as well as j.

    C.

    j can be initialized in proc2().

    D.

    The constructor can never be declared as static.

    E.

    proc2() can initialize i as well as j.

    View Answer

    Workspace

    Discuss Discuss in Forum


  5. Which of the following statements is correct?

  6. A.
    There is one garbage collector per program running in memory.
    B.
    There is one common garbage collector for all programs.
    C.
    An object is destroyed by the garbage collector when only one reference refers to it.
    D.
    We have to specifically run the garbage collector after executing Visual Studio.NET.

    View Answer

    Workspace

    Discuss Discuss in Forum


  7. Is it possible for you to prevent an object from being created by using zero argument constructor?

  8. A.
    Yes
    B.
    No

    View Answer

    Workspace

    Discuss Discuss in Forum


  9. Which of the following statements are correct about static functions?

  10. A.
    Static functions are invoked using objects of a class.
    B.
    Static functions can access static data as well as instance data.
    C.
    Static functions are outside the class scope.
    D.
    Static functions are invoked using class.

    View Answer

    Workspace

    Discuss Discuss in Forum


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

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

  12. A.

    Sample class Gate1 method

    B.

    Gate1 method

    C.

    Sample class

    D.

    Gate1 method Sample class

    E.

    Sample class Sample class

    View Answer

    Workspace

    Discuss Discuss in Forum


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

  14. A.
    A constructor cannot be declared as private.
    B.
    A constructor cannot be overloaded.
    C.
    A constructor can be a static constructor.
    D.
    A constructor cannot access static data.
    E.
    this reference is never passed to a constructor.

    View Answer

    Workspace

    Discuss Discuss in Forum


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

     namespace FreshergateConsoleApplication
     {   
       class Sample   
       {        
            public static void fun1()      
            {            
              Console.WriteLine("Gate1 method");          
            }     
            public void fun2()     
            {            
                fun1();              
                Console.WriteLine("Gate2 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);     
        }     
      }  
    }
    

     

     

  16. A.
     Gate1 method 
     123
     Gatel method
     Gate2 method
    B.
     Gate1 method 
     123 
     Gate2 method
    C.
      Gate2 method
      123
      Gate2 method  
      Gatel method
    D.
     Gatel method
     123
    E.
      Gate2 method
      123 
      Gatel method

    View Answer

    Workspace

    Discuss Discuss in Forum