.net full stack foundation coursera week 2 answers

C# Basics - Practice Quiz

1. What is C#?

  • A markup language for web development
  • A programming language for developing applications on the .NET framework
  • An operating system for mobile devices
  • A scripting language for browser automation

2. What is the current version of C#?

  • C# 5.0
  • C# 10.0
  • C# 7.0
  • C# 8.0

3. How do you execute C# code?

  • By saving the code in a text file and opening it in a web browser
  • By running the code in a command-line interface
  • By compiling the code and then running the resulting executable file
  • By running the code in an integrated development environment (IDE)

4. What is Visual Studio?

  • A programming language
  • A command-line interface for executing C# code
  • An IDE for developing applications on the .NET framework
  • An operating system for Windows-based applications

5. What is a variable in C#?

  • A fixed value that cannot be changed during program execution
  • A named memory location used to store a value that can be modified during program execution
  • A named memory location used to store a value that can be modified during program execution, and has a specific data type
  • A named function used to perform a specific operation

Conditional Statements - Practice Quiz

6. Which of the following operators has the highest precedence in C#?

  • &&
  • ==
  • ++
  • () (Correct Answer)

7. What is the result of the following code?

int x = 10;

int y = 20;

int z = x + y * 2;

  • 50
  • 60
  • 40
  • 30

8. What is the syntax for a do-while loop in C#?

  • do { } while ();
  • while { } do ();
  • for { } while ();
  • do { } while (condition);

9. What is the output of the following code?

int x = 5;

int y = 10;

if (x == y)

{

Console.WriteLine("x equals y");

}

else if (x > y)

{

Console.WriteLine("x is greater than y");

}

else

{

Console.WriteLine("y is greater than x");

}

  • x equals y
  • x is greater than y
  • y is greater than x
  • No output is generated.

10. What is the difference between a while loop and a do..while loop?

  • There is no difference between a while loop and a do..while loop.
  • A while loop checks the condition before executing the loop body, while a do..while loop checks the condition after executing the loop body at least once.
  • A while loop executes the loop body a specified number of times, while a do..while loop executes the loop body an unspecified number of times.
  • A while loop and a do..while loop are completely interchangeable and can be used interchangeably in any situation.

11. What is the result of the following expression?

8 + 2 * 3

  • 30
  • 14
  • 20
  • 18

12. What is the output of the following code snippet?

int x = 3;

int y = 5;

if (x < y)

{

Console.WriteLine("x is less than y");

}

else

{

Console.WriteLine("x is greater than or equal to y");

}

  • “x is less than y”
  • “x is greater than or equal to y”
  • “y is less than x”
  • “y is greater than or equal to x”

13. What is the output of the following code snippet?

int i = 0;

while (i < 5)

{

Console.WriteLine(i);

i++;

}

  • 0 1 2 3 4
  • 5 4 3 2 1
  • 0 0 0 0 0
  • 1 2 3 4 5

14. What is the result of the following expression: 5 + 2 * 3?

  • 11
  • 13
  • 21
  • 16

15. What is the purpose of the "else if" statement in a conditional statement?

  • To execute a block of code if a condition is false.
  • To test another condition if the previous condition tested is false.
  • To execute a block of code regardless of whether a condition is true or false.
  • To terminate a conditional statement.

16. Which of the following loops is best suited for iterating over an array in C#?

  • do..while loop
  • while loop
  • for loop
  • foreach loop

17. What is the output of the following code?

int i = 0;

while (i < 5)

{

Console.WriteLine(i);

i++;

}

  • 0 1 2 3 4
  • 1 2 3 4 5
  • 5 4 3 2 1
  • The code will result in an infinite loop.

18. Which of the following operators has the highest precedence?

  • Logical NOT (!)
  • Multiplication (*)
  • Assignment (=)
  • Increment (++)

19. Which of the following conditional statements allows for multiple conditions to be tested?

  • if
  • if..else
  • if..else if
  • switch

20. Which of the following loops will always execute at least once

  • do..while
  • while
  • for
  • foreach

21. Which of the following jump statements transfers program control to a labeled statement?

  • break
  • continue
  • goto
  • return

22. What is the output of the following code snippet?

int i = 0;

while(i < 5)

{

if(i == 2)

continue;

Console.Write(i + " ");

i++;

}

  • 0 1 2 3 4 5
  • 0 1 3 4
  • 0 1 2 3 4
  • 0 1 4 5

23. What is the value of x after the following code is executed?

int x = 5;

x *= 2 + 3;

  • 10
  • 25
  • 30
  • 35

24. What is the result of the following code?

arduino

Copy code

int i = 1;

do

{

Console.Write("{0} ", i);

i++;

} while (i <= 5);

  • 2 3 4 5
  • 2 3 4 5 6
  • 1 2 3 4
  • 1 2 3 4 5

25. Which of the following is not a jump statement in C#?

  • break
  • continue
  • return
  • print

Array & String - Practice Quiz

26.What is an array in C#?

  • A named function used to perform a specific operation
  • A fixed value that cannot be changed during program execution
  • A collection of values of the same data type, stored in contiguous memory locations
  • A named memory location used to store a value that can be modified during program execution

27. What are the types of arrays in C#?

  • Single-dimensional, multi-dimensional, and jagged arrays
  • Single-dimensional, multi-dimensional, and nested arrays
  • Linear arrays, rectangular arrays, and jagged arrays
  • Regular arrays, irregular arrays, and jagged arrays

28. What is a string in C#?

  • A named function used to perform a specific operation
  • A fixed value that cannot be changed during program execution
  • A collection of values of the same data type, stored in contiguous memory locations
  • A sequence of characters, stored as an array of characters in contiguous memory locations

29. What is the difference between the Length and Count properties of a string?

  • They are synonyms and can be used interchangeably
  • Length is used for strings with one-dimensional arrays, and Count is used for strings with multi-dimensional arrays
  • Length is used for strings, and Count is used for arrays
  • Length is a property of the string class, and Count is a method of the collection class

30. What is a string method in C#?

  • A named function used to perform a specific operation on a string
  • A pre-defined function provided by the .NET framework to manipulate strings
  • A custom function created by a developer to manipulate strings
  • A programming construct used to define a sequence of characters in a string

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.

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

  • A method that is used to destroy an object.
  • A method that is used to create an object.
  • A method that is used to modify an object.
  • Both B and C.

42. What is an abstract class in object-oriented programming?

  • A class that cannot be instantiated.
  • A class that can only be instantiated once.
  • A class that has no properties or methods.
  • Both A and C.

43. What is polymorphism in object-oriented programming?

  • The ability of an object to take on many forms.
  • The process of creating new objects.
  • The process of creating new classes from existing classes.
  • Both A and B.

44. What is method overloading in object-oriented programming?

  • The process of creating new methods from existing methods.
  • The process of creating new classes from existing classes.
  • The process of creating new objects from existing objects.
  • None of the above.

45. What is the purpose of an access modifier in object-oriented programming?

  • To determine the order in which methods are executed.
  • To control the visibility and accessibility of class members.
  • To define the behavior of an object.
  • To create a new object from an existing object.

46. What is the difference between a static method and an instance method in object-oriented programming?

  • There is no difference between a static method and an instance method.
  • A static method can be called on an object, while an instance method cannot.
  • An instance method can access non-static fields and methods of the class, while a static method cannot.
  • Both B and C.

Leave a Reply