.net full stack foundation coursera week 3 answers

Class & Interface - Practice Quiz

1. What is an abstract class in C#?

  • A class that cannot be instantiated and can only contain static methods
  • A class that can be instantiated and can only contain instance methods
  • A class that cannot be instantiated and can contain abstract and non-abstract methods
  • A class that can be instantiated and can only contain abstract methods

2. What is an interface in C#?

  • A class that cannot be instantiated and can contain both abstract and non-abstract methods
  • A class that can be instantiated and can contain both abstract and non-abstract methods
  • A contract that defines a set of methods and properties that a class must implement
  • A class that can be instantiated and can only contain abstract methods

3. What is the main difference between an interface and an abstract class in C#?

  • An interface can contain both abstract and non-abstract methods, while an abstract class can only contain abstract methods
  • An interface can be instantiated, while an abstract class cannot be instantiated
  • An interface can only contain abstract methods and properties, while an abstract class can contain both abstract and non-abstract methods
  • An abstract class can provide a default implementation for some methods, while an interface cannot provide any implementation

4. What is a static class in C#?

  • A class that can be instantiated and can contain static methods only
  • A class that can be inherited and can contain both static and non-static methods
  • A class that can be instantiated and can contain both static and non-static methods
  • A class that cannot be instantiated and can contain only static methods and properties

5. Which of the following statements about indexers in C# is correct?

  • Indexers are used to access properties of an object using an index
  • Indexers can only be used with arrays
  • Indexers can only be used to retrieve data from an object, not to modify it
  • All of the above statements are true

Property & Indexers -Practice Quiz

6. What is the purpose of an exception in C#?

  • To terminate the program execution
  • To handle errors or unexpected situations in a program
  • To skip a block of code
  • To reduce the size of the program

7. What is a property in C#?

  • A method that returns a specific type of object
  • A type of exception used for handling null values
  • A way to add metadata to a program element
  • A member of a class or struct that provides access to a private field

8. What is an indexer in C#?

  • A class that provides a set of methods to handle exceptions thrown by the application.
  • A class that allows a developer to attach additional data to a type or method.
  • A class that provides a convenient way to encapsulate an array of values and access them using an index.
  • A class that provides a way to define a single property that can be accessed using multiple keys or indexes.

Advanced C# - Graded Quiz

9. What is an extension method in C#?

  • A method that can only be used within the class where it is defined.
  • A method that can be called without an object instance.
  • A method that is marked with the “static” keyword.
  • A method that extends the functionality of an existing class.

10. What is an anonymous type in C#?

  • A type that is defined using the “class” keyword.
  • A type that has a name that is generated at runtime.
  • A type that is defined on the fly, without an explicit class definition.
  • A type that cannot be used as a parameter or return type in a method.

11. What is the difference between "var" and "dynamic" in C#?

  • There is no difference between “var” and “dynamic”.
  • “Var” is used to declare a variable with an inferred type, while “dynamic” is used to declare a variable with an unknown type.
  • “Var” is used to declare a variable with a known type, while “dynamic” is used to declare a variable with an inferred type.
  • “Var” is used to declare a variable with an inferred type, while “dynamic” is used to declare a variable with a type that is determined at runtime.

12. What is the purpose of an anonymous type in C#?

  • To define a new class with a specific set of properties.
  • To define a new method with a specific signature.
  • To define a new variable with a specific type.
  • To define a new namespace with a specific set of classes.

13. What is the difference between the var keyword and the dynamic keyword in C#?

  • The var keyword is used for strongly typed variables, while the dynamic keyword is used for weakly typed variables.
  • The var keyword is used for reference types, while the dynamic keyword is used for value types.
  • The var keyword is used to declare variables that can be reassigned, while the dynamic keyword is used to declare variables that are constant.
  • The var keyword is used for variables whose types are determined at compile-time, while the dynamic keyword is used for variables whose types are determined at runtime.

14. What is the difference between "var" and "dynamic" in C#?

  • There is no difference between “var” and “dynamic”.
  • “Var” is used to declare a variable whose type is inferred by the compiler, while “dynamic” is used to declare a variable whose type can change at runtime
  • “Var” is used to declare a variable of a specific type, while “dynamic” is used to declare a variable of any type.
  • Both A and B.

15. What is the difference between the "var" and "dynamic" keywords in C#?

  • There is no difference; they are interchangeable.
  • “Var” is used for statically typed objects, while “dynamic” is used for dynamically typed objects.
  • “Var” is used for dynamically typed objects, while “dynamic” is used for statically typed objects.
  • “Var” is used for anonymous types, while “dynamic” is used for named types.

16. What is a delegate in C#?

  • A type that represents a reference to a method with a specific signature.
  • A keyword used to define a new class.
  • A modifier used to indicate a method can be called from any class in the same namespace.
  • A keyword used to indicate a method is a constructor.

17. What is an anonymous method in C#?

  • A method with no parameters.
  • A method with no name.
  • A method that is defined as static.
  • A method that is automatically generated by the compiler.

18. What is the purpose of an expression tree in C#?

  • To represent a compiled method as a tree of nodes.
  • To store metadata about a compiled assembly.
  • To optimize the performance of a compiled method.
  • To allow LINQ queries to be translated into code.

19. What is the purpose of the "var" keyword in C#?

  • To specify the type of a variable.
  • To indicate that a variable cannot be changed once it has been assigned a value.
  • To indicate that a variable should be initialized with a default value.
  • To allow developers to declare variables without specifying their types explicitly.

20. What is the purpose of an event in C#?

  • To define a new class.
  • To encapsulate a method call and its parameters.
  • To provide a mechanism for one object to notify other objects when an event occurs.
  • To define a block of code that can be called from multiple places in a program.

21. What is a lambda expression in C#?

  • A way to define a new class.
  • A way to define a new variable.
  • A way to define an anonymous method.
  • A way to define a property.

22. What is an expression tree in C#?

  • A data structure that represents a lambda expression as a tree of expression nodes.
  • A mechanism for passing a block of code as a parameter to a method.
  • A way to define a new class.
  • A way to define a new variable.

23. What is the difference between var and dynamic in C#?

  • var is used for static type inference, while dynamic is used for dynamic type binding.
  • var is used for dynamic type binding, while dynamic is used for static type inference.
  • There is no difference between var and dynamic in C#.
  • var and dynamic are both used for static type inference.

24. What is an expression tree in C#?

  • A tree data structure that represents a lambda expression.
  • A tree data structure that represents a list of expressions.
  • A tree data structure that represents a sequence of executable instructions.
  • A tree data structure that represents a data object with multiple properties.

Leave a Reply