Curioustab
Aptitude
General Knowledge
Verbal Reasoning
Computer Science
Interview
Take Free Test
Aptitude
General Knowledge
Verbal Reasoning
Computer Science
Interview
Take Free Test
Classes and Objects Questions
Instance fields, instance methods, and accessibility in C# — consider the code and choose the correct statements. namespace CuriousTabConsoleApplication { 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); // static-style call (invalid) s.fun(1, 5); // instance call (valid) } } } Which of the following statement sets are correct?
C#.NET — Default accessibility of class members and intra-class access rules. Which of the following statements are correct? Data members of a class are by default public. Data members of a class are by default private. Member functions (methods) of a class are by default public. A private function of a class can access a public function within the same class. Member functions of a class are by default private.
Programming paradigms — pick the correct statement. Which statement is accurate about Object-Oriented Programming (OOP), structured programming, and C#.NET?
C#.NET value types, new, and ToString(): analyze this snippet. int i; int j = new int(); i = 10; j = 20; string str; str = i.ToString(); str = j.ToString(); Which statement best describes this code?
C#.NET — Does the this reference exist for instance (non-static) method calls?
C#.NET — Understanding this and instance identity in method calls. Consider: namespace CuriousTabConsoleApplication { class Sample { int i, j; public void SetData(int ii, int jj) { this.i = ii; this.j = jj; } } class MyProgram { static void Main(string[] args) { Sample s1 = new Sample(); s1.SetData(10, 2); Sample s2 = new Sample(); s2.SetData(5, 10); } } } Which statement is correct?
C#.NET — Identify valid ways to create an object of class Sample. Consider the following possibilities: Sample s = new Sample(); Sample s; Sample s; s = new Sample(); s = new Sample(); Which options correctly create an object?
C#.NET — Access modifiers and member access within a class. Given: class Sample { private int i; public float j; private void DisplayData() { Console.WriteLine(i + " " + j); } public void ShowData() { Console.WriteLine(i + " " + j); } } Which statement is correct?
C#.NET — Objects, instance data, and shared behavior: choose the correct statements about a user-defined class Sample. Statements: All objects of Sample will always have exactly the same data. Objects of Sample may have the same or different data. Whether objects of Sample have the same or different data depends on a Visual Studio project setting. Conceptually, each object of Sample has its own instance data and exposes the instance member functions (behavior) of Sample. All objects of Sample share one copy of member functions.
C#.NET — What actually happens in: sample c; c = new sample(); Choose the correct interpretation.
C#.NET — Trace the output of this instance-method call. namespace CuriousTabConsoleApplication { class Sample { int i; float j; public void SetData(int i, float j) { this.i = i; this.j = j; } public void Display() { Console.WriteLine(i + " " + j); } } class MyProgram { static void Main(string[] args) { Sample s1 = new Sample(); s1.SetData(36, 5.4f); s1.Display(); } } } What will be printed?
Fundamentals of classes and objects in C#.NET: which statement is correct? Consider how classes (reference types) and their objects are created and stored in memory in C#. Choose the most accurate statement about classes/objects and their allocation.
C#.NET object creation semantics: given class Student s1, s2; // Student is a user-defined class s1 = new Student(); s2 = new Student(); Which statement best describes what is true about s1 and s2 and the created objects?
Core facts about classes and objects in C#: select the correct statements. 1) Instance members of a class can be accessed only through an object of that class. 2) A class can contain only instance data and instance member functions. 3) All objects created from a class occupy an equal number of bytes in memory. 4) A class can contain Friend (internal) functions. 5) A class is a blueprint/template from which objects are created.
The this reference in C#: which statements are correct? 1) this can be modified inside an instance member. 2) Static functions never receive this. 3) Instance member functions always receive this. 4) this continues to exist after control returns from an instance member. 5) When calling an instance member function we do not pass this explicitly.
Predict the output (parameter shadowing): namespace CuriousTabConsoleApplication { class Sample { int i; Single j; public void SetData(int i, Single j) { i = i; j = j; } public void Display() { Console.WriteLine(i + " " + j); } } class MyProgram { static void Main(string[] args) { Sample s1 = new Sample(); s1.SetData(10, 5.4f); s1.Display(); } } }