QUESTION 1 OF 11
print("Total price ${price}"); is the same as print("Total price $price");
- Answer: True
- Explanation: Both forms are valid and equivalent. Dart supports string interpolation using the $ symbol followed by a variable name within a string. The curly braces {} are optional when referencing a variable directly without any additional text or expressions.

 

 

 

 


QUESTION 2 OF 11
What does collection for do?
1. It allows us to run a `for` loop while constructing a list
2. It allows us to run a `for` loop after constructing a list

- Answer: 1. It allows us to run a for loop while constructing a list.
- Explanation: The collection for syntax in Dart allows us to create a list by executing a for loop and defining the elements of the list within the loop. This is useful when you want to transform or filter elements while constructing the list.

 

 

 

 


QUESTION 3 OF 11
This code will compile:

void main(){
    Map<String, int> dir =  {
        "1": 1,
        "2":2,
        3:3,
        "4":4
    };
}

 

- Answer: False
- Explanation: The provided code will not compile. In the given Map declaration, the key "3" is assigned the value 3, which is an integer. However, the declared type of the Map is Map<String, int>, which means it should have String keys and int values. To fix this, either change the key "3" to "3", or change the value 3 to an int type, such as 3: 3.

 

 

 

 


QUESTION 4 OF 11
What is the difference between a Set and a List?
1. Elements on a List are unique. Elements on a Set are not.
2. Elements on a Set are unique. Elements on a List are not.

- Answer: 2. Elements on a Set are unique. Elements on a List are not.
- Explanation: In Dart, a Set is an unordered collection of unique elements, meaning it cannot contain duplicate values. On the other hand, a List is an ordered collection that allows duplicate values.

 

 

 

 


QUESTION 5 OF 11
Is this a set or a list?

var numbers = [1, 2, 3];

1. List
2. Set
- Answer: 1. List
- Explanation: The provided code creates a List named numbers containing the elements 1, 2, and 3. The square brackets [] are used to create a list literal in Dart.

 

 

 



QUESTION 6 OF 11
Is this a set or a list?

var numbers = {1, 2, 3};

1. List
2. Set

- Answer: Set
- Explanation: The provided code creates a Set named numbers containing the elements 1, 2, and 3. The curly braces {} are used to create a set literal in Dart.

 

 

 

 


QUESTION 7 OF 11
What does collection if do?
1. It allows us to run an `if` while constructing a list
2. It allows us to run an `if` after constructing a list

- Answer: It allows us to run an if while constructing a list.
- Explanation: The collection if syntax in Dart allows us to conditionally include elements in a collection while constructing it. It provides a way to filter elements based on a condition during the collection creation process.

 

 

 

 


QUESTION 8 OF 11
What does the type num represent?
1. Positive and negative numbers
2. Positive numbers
3. Positive and negative integers and doubles
4. Positive and negative doubles

- Answer: 3. Positive and negative integers and doubles.
- Explanation: The num type in Dart represents any numeric value, including positive and negative integers, as well as positive and negative floating-point (decimal) numbers (doubles).

 

 

 

 


QUESTION 9 OF 11
This code will compile:

void main(){
    num age = 18;
    age = 1.11;
}

- Answer: True
- Explanation: The provided code will compile without any errors. In Dart, the num type is a superclass of both int and double, so it can hold both integer and floating-point values. In the given code, the variable age is initially assigned an integer value of 18 and later reassigned a floating-point value of 1.11, which is allowed.

 

 

 

 


QUESTION 10 OF 11
Doing List<bool> x = [true]; is the same as var x = [true];

List<bool> x = [true];
var x = [true];

- Answer: True
- Explanation: Both forms are valid and equivalent. In Dart, when initializing a variable, you can explicitly declare the type using the List<bool> syntax, or you can rely on type inference by using var and letting Dart automatically determine the type based on the assigned value.

 

 

 

 


QUESTION 11 OF 11
This code will output: "Hi! My name is NICO !:

void main(){
    var name = 'nico';
    print("Hi! My name is $name.toUpperCase() !");
}

- Answer: False
- Explanation: The code will not output "Hi! My name is NICO !". In Dart string interpolation, expressions within the ${} syntax are evaluated and their results are interpolated into the string. However, in the provided code, the expression $name.toUpperCase() is inside the string literal and will not be evaluated as a method call. To correctly invoke the toUpperCase() method, the code should be modified as follows:

void main(){
    var name = 'nico';
    print("Hi! My name is ${name.toUpperCase()} !");
}

By enclosing name.toUpperCase() within ${} and placing it outside the quotes, the method will be invoked and its result will be interpolated into the string, resulting in the desired output.

 

 

 

 

+ Recent posts