Classes and Objects Questions

Practice Classes and Objects MCQs with answers and explanations. Page 1 of 1.

Category
C# Programming
Topic
Classes and Objects
Page
1 / 1
Mode
Practice

Questions

Open any question to view the answer and explanation.

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?
Open
View answer
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.
Open
View answer
Programming paradigms — pick the correct statement. Which statement is accurate about Object-Oriented Programming (OOP), structured programming, and C#.NET?
Open
View answer
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?
Open
View answer
C#.NET — Does the this reference exist for instance (non-static) method calls?
Open
View answer
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?
Open
View answer
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?
Open
View answer
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?
Open
View answer
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.
Open
View answer
C#.NET — What actually happens in: sample c; c = new sample(); Choose the correct interpretation.
Open
View answer
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?
Open
View answer
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.
Open
View answer
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?
Open
View answer
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.
Open
View answer
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.
Open
View answer
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(); } } }
Open
View answer

Practice smarter

Solve a few questions daily and revisit weak topics regularly to improve accuracy.