Skip to content
QuiznExam

Classes and Objects in C#

Test your knowledge of classes and objects in C#, including class definitions, object creation, fields, methods, constructors, properties, and access modifiers.

15
Questions
12 min
Time limit
Medium
Difficulty

No sign-up needed · Last updated:

Save your score

At least 8 characters.

Forgot password?

Related quizzes

All 15 questions and answers Spoilers: this shows the questions and answers. Try the quiz first! Open
  1. 1. What is a class in C#?

    • A. A blueprint for creating objects
    • B. A database table
    • C. A loop structure
    • D. A namespace only
    Show answer

    A. A blueprint for creating objects

    A class defines the data and behavior that objects created from it can have.

  2. 2. What is an object in C#?

    • A. An instance of a class
    • B. A method declaration
    • C. A namespace
    • D. A data type keyword
    Show answer

    A. An instance of a class

    An object is an instance of a class and can contain its own state and access the behavior defined by the class.

  3. 3. Which keyword is used to define a class in C#?

    • A. class
    • B. object
    • C. define
    • D. type
    Show answer

    A. class

    The class keyword is used to declare a class in C#.

  4. 4. Which keyword is commonly used to create an object of a class?

    • A. new
    • B. create
    • C. object
    • D. instance
    Show answer

    A. new

    The new keyword creates an instance of a class and invokes an appropriate constructor.

  5. 5. Which statement correctly creates an object of a class named Car?

    • A. Car car = new Car();
    • B. Car car = create Car();
    • C. object Car = new();
    • D. new Car car;
    Show answer

    A. Car car = new Car();

    This syntax declares a Car reference named car and creates a new Car object.

  6. 6. Which member of a class is used to define behavior?

    • A. Method
    • B. Field only
    • C. Namespace
    • D. Assembly
    Show answer

    A. Method

    Methods define operations or behavior that objects of a class can perform.

  7. 7. What is a constructor in C#?

    • A. A special member used to initialize an object
    • B. A method that must return int
    • C. A property used only for reading data
    • D. A class that cannot create objects
    Show answer

    A. A special member used to initialize an object

    A constructor is invoked when an object is created and is commonly used to initialize its state.

  8. 8. What is the name of a constructor in a C# class?

    • A. It must have the same name as the class
    • B. It must always be named Constructor
    • C. It must always be named init
    • D. It must have the same name as the namespace
    Show answer

    A. It must have the same name as the class

    A constructor has the same name as its containing class and does not have a return type.

  9. 9. Which access modifier makes a class member accessible from anywhere that has access to the containing type?

    • A. public
    • B. private
    • C. protected
    • D. internal
    Show answer

    A. public

    A public member is accessible from code that can access the containing type, subject to other language rules.

  10. 10. What is the default access level of a class member when no access modifier is specified?

    • A. private
    • B. public
    • C. protected
    • D. internal
    Show answer

    A. private

    Class members are private by default when no access modifier is explicitly specified.

  11. 11. Which feature allows a class to expose controlled access to its data?

    • A. Properties
    • B. Namespaces
    • C. Assemblies
    • D. Comments
    Show answer

    A. Properties

    Properties provide a controlled way to get or set values associated with an object.

  12. 12. Which syntax correctly declares an auto-implemented property in C#?

    • A. public string Name { get; set; }
    • B. public string Name();
    • C. property string Name;
    • D. string Name => set;
    Show answer

    A. public string Name { get; set; }

    An auto-implemented property can use get and set accessors without explicitly declaring a backing field.

  13. 13. What does the this keyword commonly refer to inside an instance member of a C# class?

    • A. The current object instance
    • B. The parent namespace
    • C. The next object created
    • D. The current method only
    Show answer

    A. The current object instance

    Inside an instance member, this refers to the current instance of the class.

  14. 14. What happens when a class is declared with the static keyword?

    • A. It cannot be instantiated directly
    • B. It must always contain a constructor with parameters
    • C. It automatically inherits from every class
    • D. All its members become private
    Show answer

    A. It cannot be instantiated directly

    A static class cannot be instantiated and can contain only static members.

  15. 15. Which statement about classes and objects in C# is correct?

    • A. A class defines a type, while an object is an instance of that type
    • B. Every class must contain exactly one object
    • C. Objects cannot have state
    • D. A class can only contain methods and cannot contain properties
    Show answer

    A. A class defines a type, while an object is an instance of that type

    A class defines the structure and behavior of a type, while objects are instances created from that type.