Classes and Objects

Q1:
Which of the following statements is correct about the C#.NET code snippet given below?
namespace AptitudeCrackConsoleApplication
{ 
    class Sample
    { 
        public int index; 
        public int[] arr = new int[10]; 
        
        public void fun(int i, int val)
        { 
            arr[i] = val;
        }
    }
     
    class MyProgram
    { 
        static void Main(string[] args)
        {
            Sample s = new Sample(); 
            s.index = 20; 
            Sample.fun(1, 5); 
            s.fun(1, 5); 
        } 
    } 
}

A s.index = 20 will report an error since index is public.

B The call s.fun(1, 5) will work correctly.

C Sample.fun(1, 5) will set a value 5 in arr[ 1 ].

D The call Sample.fun(1, 5) cannot work since fun() is not a shared function.

E arr being a data member, we cannot declare it as public.

ANS:B - The call s.fun(1, 5) will work correctly.

No answer description is available. Let's discuss.



img not found
img

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.