C# Fundamentals Graded Quiz

31. What is an access modifier in object-oriented programming?

  • A keyword used to define a new class.
  • A way to specify a value or behavior for an object.
  • A way to control the visibility of a class, method, or field.
  • A way to define a variable that can only be accessed within a method.

32. What is a constructor in object-oriented programming?

  • A method that is inherited from a parent class.
  • A method that returns a value.
  • A special method that is used to create an instance of a class and initialize its state.
  • A method that is used to override the behavior of a parent class method.

33. What is inheritance in object-oriented programming?

  • The process of hiding the internal implementation of an object and exposing only the necessary functionality.
  • The process of defining a new class based on an existing class.
  • The process of creating multiple instances of a class.
  • The process of changing the value of a variable at runtime.

34. What is a method in object-oriented programming?

  • A special type of variable that can store multiple values.
  • A keyword used to define a new class.
  • A special type of variable that can store multiple methods.
  • A function that is associated with an object or class and can be called to perform a specific task.

35. What is a structure in object-oriented programming?

  • A data type that is used to store variables of different data types.
  • A method that is used to change the value of a variable.
  • A keyword used to define a new class.
  • A type of user-defined data type that is similar to a class, but with the key difference that its members are public by default.

36. Which of the following is true about constructors in object-oriented programming?

  • A constructor is used to destroy objects when they are no longer needed.
  • A constructor is used to create objects and allocate memory for them.
  • A constructor is used to modify existing objects.
  • All of the above.

37. What is the purpose of inheritance in object-oriented programming?

  • To hide the implementation details of a class.
  • To create new classes by deriving from existing classes.
  • To provide a mechanism for storing and accessing data.
  • Both A and B.

38. Which of the following is an access modifier in object-oriented programming?

  • Private
  • Public
  • Protected
  • All of the above.

39. What is the difference between a method and a function in object-oriented programming?

  • There is no difference between a method and a function.
  • A method is a function that is called on an object, while a function is not associated with any object.
  • A function is a method that is called on an object, while a method is not associated with any object.
  • Both A and B.

40. What is the difference between private and protected access modifiers in object-oriented programming?

  • There is no difference between private and protected access modifiers.
  • Private members can be accessed by any class, while protected members can only be accessed by subclasses.
  • Protected members can be accessed by any class, while private members can only be accessed by subclasses.
  • Private members can only be accessed by the same class, while protected members can be accessed by the same class and its subclasses.

Leave a Reply