Dart Online Quiz Test

Welcome to our Dart Online Quiz Test! This quiz comprises 30 MCQs (Multiple-Choice Questions) to evaluate your knowledge of Dart, a versatile and efficient programming language developed by Google. The Dart is primarily used for building web, server, and mobile applications and is particularly known for being the programming language behind Flutter. 

Whether you’re a newcomer to Dart looking to test your initial understanding or an experienced programmer aiming to refine your skills, this quiz provides a great opportunity to assess and enhance your Dart programming abilities. Let’s see how much you know about Dart—start the quiz and challenge yourself!

1. How do you declare a constant in Dart?

a) const double pi = 3.14;
b) var pi = const 3.14;
c) final pi = 3.14;
d) static const pi = 3.14;

2. What is the correct way to create a list in Dart?

a) List<String> names = ['Alice', 'Bob', 'Charlie'];
b) Array<String> names = ['Alice', 'Bob', 'Charlie'];
c) List<String> names = new List['Alice', 'Bob', 'Charlie'];
d) var names = ['Alice', 'Bob', 'Charlie'];

3. How do you define a function in Dart that returns an integer?

a) int addNumbers(int a, int b) { return a + b; }
b) function addNumbers(int a, int b): int { return a + b; }
c) int addNumbers(a, b) => a + b;
d) define addNumbers(int a, int b) { return a + b; }

4. Which Dart feature allows you to execute code asynchronously?

a) sync
b) wait
c) future
d) async

5. How do you concatenate strings in Dart?

String greeting = 'Hello, ';
String name = 'World';
print(greeting + name);
a) greeting + name
b) greeting.concat(name)
c) greeting.append(name)
d) greeting & name

6. What is the use of the new keyword in Dart?

a) It is mandatory to use when instantiating objects.
b) It is optional when instantiating objects.
c) It creates a static instance of a class.
d) It is used to declare new types.

7. How do you create a map in Dart?

a) Map<String, int> phoneBook = {'Alice': 12345, 'Bob': 67890};
b) {'Alice': 12345, 'Bob': 67890};
c) Map['Alice': 12345, 'Bob': 67890];
d) new Map('Alice': 12345, 'Bob': 67890);

8. What does the ??= operator do in Dart?

int? a;
a ??= 3;
a) Assigns a value to a if a is not null
b) Checks if a is null and, if so, assigns it the value 3
c) Multiplies a by 3 if a is not null
d) None of the above

9. How do you handle exceptions in Dart?

a) try { ... } handle { ... }
b) try { ... } catch (e) { ... }
c) try { ... } exception (e) { ... }
d) error { ... } catch { ... }

10. What is Dart's null-aware operator?

a) ?
b) !!
c) ??
d) ::

11. How do you declare a class in Dart?

a) class Person { String name; int age; Person(this.name, this.age); }
b) new class Person { String name; int age; Person(this.name, this.age); }
c) struct Person { String name; int age; Person(this.name, this.age); }
d) define Person { String name; int age; Person(this.name, this.age); }

12. How do you declare a named constructor in Dart?

a) Point.origin() { x = 0; y = 0; }
b) new Point() { x = 0; y = 0; }
c) Point() { x = 0; y = 0; }
d) constructor Point() { x = 0; y = 0; }

13. What is Dart's default value for uninitialized variables?

a) 0
b) null
c) false
d) undefined

14. How do you check for equality in Dart?

a) a == b
b) a.equals(b)
c) a === b
d) equals(a, b)

15. What is the output of the following code?

var numbers = [1, 2, 3];
numbers.add(4);
print(numbers.length);
a) 3
b) 4
c) 5
d) An error

16. How do you import a core library in Dart?

a) import 'dart:math';
b) include 'dart:math';
c) require 'dart:math';
d) load 'dart:math';

17. What is the use of the extends keyword?

class Employee extends Person {
    int employeeId;
    Employee(String name, int age, this.employeeId) : super(name, age);
}
a) To create an interface
b) To inherit from another class
c) To indicate that a method should be overridden
d) To declare a variable

18. What does the super keyword do?

a) Calls a method in the current class
b) Deletes an object
c) Calls the constructor of the superclass
d) Throws an exception

19. What is the output of the following code?

int x = 10;
int y = 3;
print(x ~/ y);
a) 3.33
b) 3
c) 4
d) 3.0

20. What is the purpose of the async keyword in Dart?

Future<void> fetchUserOrder() async {
    return await fetchUserData();
}
a) To mark a function as synchronous
b) To define a variable
c) To mark a function that performs asynchronous operations
d) To create a new thread

21. Which Dart collection is a dynamically sized list of elements with a single type?

a) Array
b) Set
c) Map
d) List

22. What does the @override annotation do?

class Employee extends Person {
    @override
    void describe() {
        print('Employee describe');
    }
}
a) It indicates that the method changes the behavior of a superclass method
b) It makes the method abstract
c) It prevents the method from being overridden
d) It automatically calls the method from the superclass

23. How do you declare a list with a fixed length in Dart?

a) List<int> fixedList = new List(5);
b) List<int> fixedList = [5];
c) List<int> fixedList = List.filled(5, 0);
d) List<int> fixedList = List(5);

24. How do you ensure a function in Dart returns a value on all execution paths?

a) Using the final keyword
b) Using the ensure keyword
c) By having return statements on all conditional branches
d) Dart automatically ensures this

25. What is the result of using the spread operator in Dart?

var list = [1, 2, 3];
var list2 = [0, ...list];
a) [1, 2, 3, 0]
b) [0, 1, 2, 3]
c) [0, [1, 2, 3]]
d) It throws an error

26. How do you convert a string to an integer in Dart?

a) int.parse("1234")
b) "1234".toInt()
c) Integer.parseInt("1234")
d) parse.int("1234")

27. How do you declare a map in Dart?

a) Map shop = {"apple": 2, "banana": 3};
b) Map<String, int> shop = new Map();
c) Map<String, int> shop = {"apple": 2, "banana": 3};
d) Dictionary<String, int> shop = {"apple": 2, "banana": 3};

28. Which keyword is used to define a constant in Dart?

a) var
b) const
c) final
d) static

29. What is the correct way to declare a variable in Dart that you might want to change later?

a) var age = 25;
b) final age = 25;
c) const age = 25;
d) int age = 25;

30. How do you create a list of strings in Dart?

a) List<String> names = new List();
b) List<String> names = ["Alice", "Bob", "Charlie"];
c) String[] names = ["Alice", "Bob", "Charlie"];
d) ArrayList<String> names = ["Alice", "Bob", "Charlie"];

Comments

  1. I start it recently, I would like to attend after my learning

    ReplyDelete

Post a Comment

Leave Comment