C# - Classes and Objects Questions and Answers

Practice Mode
Showing 10 of 37 questions
Q11
Which of the following statements are correct about objects of a user-defined class called Sample?     All objects of Sample class will always have exactly same data.     Objects of Sample class may have same or different data.     Whether objects of Sample class will have same or different data depends upon a Project Setting made in Visual Studio.NET.     Conceptually, each object of Sample class will have instance data and instance member functions of the Sample class.     All objects of Sample class will share one copy of member functions.
  • A 1, 3
  • B 2, 4
  • C 4, 5
  • D 3, 5
Answer: Option C
Q12
Which of the following statements is correct about classes and objects in C#.NET?
  • A Class is a value type.
  • B Since objects are typically big in size, they are created on the stack.
  • C Objects of smaller size are created on the heap.
  • D Smaller objects that get created on the stack can be given names.
Answer: Option
Q13
Which keyword is used to define a class in C#?
  • A object
  • B class
  • C struct
  • D define
Answer: Option B
Explanation: Classes in C# are declared using the class keyword.
Q14
What is an instance of a class called?
  • A Object
  • B Method
  • C Field
  • D Property
Answer: Option A
Explanation: Objects are runtime instances of classes.
Q15
Which access modifier allows members to be visible only within the same class?
  • A public
  • B private
  • C protected
  • D internal
Answer: Option B
Explanation: Private members are accessible only within the class itself.
Q16
What is the entry point method for a C# program?
  • A Start()
  • B Execute()
  • C Main()
  • D Run()
Answer: Option C
Explanation: The Main() method is the starting point of execution.
Q17
Which keyword is used to create an object in C#?
  • A object
  • B create
  • C new
  • D instance
Answer: Option C
Explanation: The new keyword instantiates a class.
Q18
What is the default access modifier for class members in C#?
  • A public
  • B protected
  • C private
  • D internal
Answer: Option C
Explanation: Members inside a class are private unless otherwise specified.
Q19
Which of the following can be used to initialize class variables during object creation?
  • A Properties
  • B Constructors
  • C Methods
  • D Accessors
Answer: Option B
Explanation: Constructors run automatically when an object is created.
Q20
What happens if no constructor is defined in a class?
  • A The program fails to compile
  • B A default constructor is added by C#
  • C An error is thrown
  • D Nothing happens
Answer: Option B
Explanation: C# creates an implicit parameterless constructor.
Questions and Answers for Competitive Exams Various Entrance Test