Podcast
Questions and Answers
What is the purpose of a constructor in a class?
What is the purpose of a constructor in a class?
- To set the access modifier for a field
- To create a new instance of the class (correct)
- To define a method that can be called multiple times
- To initialize fields with default values
What happens if you do not create a class constructor yourself?
What happens if you do not create a class constructor yourself?
- The compiler will throw an error
- The class cannot be instantiated
- The fields are initialized with default values
- C# creates one for you (correct)
What is the purpose of constructor parameters?
What is the purpose of constructor parameters?
- To define the return type of the constructor
- To create a new instance of the class
- To declare a method inside the constructor
- To initialize fields with specific values (correct)
What is the name of the constructor in the following code: class Car { ... }
?
What is the name of the constructor in the following code: class Car { ... }
?
How many parameters can a constructor have?
How many parameters can a constructor have?
What is the output of the following code: Car Ford = new Car ( "Mustang", "Red", 1969); Console.WriteLine( Ford.color + " " + Ford.year + " " + Ford.model);
?
What is the output of the following code: Car Ford = new Car ( "Mustang", "Red", 1969); Console.WriteLine( Ford.color + " " + Ford.year + " " + Ford.model);
?
What is the purpose of a constructor in a class?
What is the purpose of a constructor in a class?
How do you access a method in a class?
How do you access a method in a class?
What is the difference between a static method and a public method?
What is the difference between a static method and a public method?
What is the purpose of a field in a class?
What is the purpose of a field in a class?
Why did we declare the fullThrottle
method as public and not static?
Why did we declare the fullThrottle
method as public and not static?
What is the syntax to call a method in a class?
What is the syntax to call a method in a class?
What is the purpose of a constructor in a class?
What is the purpose of a constructor in a class?
What is the advantage of using a constructor in the example given?
What is the advantage of using a constructor in the example given?
What is the access modifier that allows access to a class from any other class?
What is the access modifier that allows access to a class from any other class?
What is created when you use the new keyword in C#?
What is created when you use the new keyword in C#?
Which of the following access modifiers allows access to a class only within the same class?
Which of the following access modifiers allows access to a class only within the same class?
What is the purpose of overloading a constructor in C#?
What is the purpose of overloading a constructor in C#?