




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





























































































Question 1. Which keyword is used to declare a compile‑time constant value that cannot be changed after its initialization? A) var B) final C) const D) static Answer: C Explanation: const creates a compile‑time constant whose value is fixed and known at compile time, unlike final which is run‑time immutable. Question 2. In Dart’s null‑safety system, what does the postfix ! operator do? A) Declares a nullable variable B) Forces a nullable expression to be treated as non‑null, throwing at runtime if it is null C) Marks a variable as required in a constructor D) Indicates a late‑initialized variable Answer: B Explanation: The bang operator (!) asserts that the operand is non‑null; if it is null at runtime, a LateError is thrown. Question 3. Which of the following is a primitive numeric type that stores floating‑point numbers? A) int B) double C) num D) bool Answer: B
Explanation: double represents 64‑bit IEEE‑754 floating‑point numbers. int is for integers, num is a supertype of both. Question 4. What is the result of the expression 5 is int? A) true B) false C) throws a compile‑time error D) null Answer: A Explanation: The type‑test operator is checks if the left operand is of the specified type; 5 is an int, so the result is true. Question 5. Which operator has the highest precedence in Dart? A) && B) ?? C) == D) ++ (postfix) Answer: D Explanation: The postfix increment (++) has higher precedence than logical (&&), null‑coalescing (??), and equality (==) operators. Question 6. In a switch statement, which keyword must be used to exit a case without falling through to the next one? A) break B) continue C) return D) exit
C) Map D) Queue Answer: B Explanation: A Set stores unordered unique items and offers O(1) average‑time lookup. Question 10. Given var numbers = [1, 2, 3, 4];, what does numbers.where((n) => n.isOdd).toList() return? A) [1, 3] B) [2, 4] C) [1, 2, 3, 4] D) [] Answer: A Explanation: The where method filters elements that satisfy the predicate; isOdd is true for 1 and 3. Question 11. Which operator is used to spread the elements of an existing list into a new list literal? A) ... B) ** C) :: D) ?? Answer: A Explanation: The spread operator (...) inserts all elements of an iterable into another collection literal. Question 12. In Dart, what does the late keyword indicate when placed before a variable declaration?
A) The variable can be null B) The variable will be initialized lazily, after its declaration but before first use C) The variable is a compile‑time constant D) The variable is static across all instances Answer: B Explanation: late defers initialization until the variable is first accessed, allowing non‑nullable variables to be assigned later. Question 13. Which of the following correctly defines a constant constructor for a class Point with two final fields x and y? A) class Point { final int x; final int y; const Point(this.x, this.y); } B) class Point { int x; int y; const Point(this.x, this.y); } C) class Point { final int x; final int y; Point(this.x, this.y); } D) class Point { final int x; final int y; const Point({required this.x, required this.y}); } Answer: A Explanation: A constant constructor must initialize all final fields and be prefixed with const. Option D is also valid but uses named parameters; however the simplest correct answer is A. Question 14. How does a mixin differ from a regular class when used with the with keyword? A) A mixin cannot have a constructor B) A mixin can only be applied to abstract classes C) A mixin must extend Object directly D) A mixin can be instantiated on its own Answer: A Explanation: Mixins cannot declare constructors; they are intended to be “mixed into” other classes to provide reusable behavior.
Question 18. Which method is used to listen to events from a Stream and handle errors separately? A) listen(onData, onError: ...) B) forEach() C) map() D) where() Answer: A Explanation: The listen method accepts callbacks for data (onData), errors (onError), and completion (onDone). Question 19. In Dart, what is the primary purpose of an isolate? A) To provide synchronized access to shared memory B) To enable true parallel execution by running code in separate memory heaps C) To replace the event loop for asynchronous code D) To simplify exception handling across async functions Answer: B Explanation: Isolates run in separate memory spaces, allowing true parallelism without shared mutable state. Question 20. Which of the following statements about SendPort and ReceivePort is true? A) SendPort can only send strings, while ReceivePort can receive any type. B) Data sent through a SendPort must be a simple value that can be serialized. C) ReceivePort automatically creates a new isolate. D) SendPort and ReceivePort are interchangeable. Answer: B
Explanation: Communication between isolates uses message passing; only values that can be transferred (primitives, simple collections, etc.) are allowed. Question 21. In a pubspec.yaml file, which section is used to specify packages needed only for development and testing? A) dependencies B) dev_dependencies C) dependency_overrides D) environment Answer: B Explanation: dev_dependencies lists packages required for development, such as testing frameworks, but not for the production app. Question 22. Which version constraint allows any version greater than or equal to 2.0.0 but less than 3.0.0? A) ^2.0.0 B) >=2.0.0 <3.0.0 C) ~2.0.0 D) 2.0.0 Answer: B Explanation: The explicit range >=2.0.0 <3.0.0 enforces compatibility with any 2.x version, while ^2.0.0 behaves similarly but excludes pre‑release versions. Question 23. What does the show keyword do in an import directive? A) Hides the listed symbols from the imported library. B) Exposes only the listed symbols from the imported library. C) Renames the imported library.
D) json.parse() Answer: A Explanation: json.encode() serializes a Dart object (typically a Map or List) into a JSON‑formatted string. Question 27. What is the purpose of the Uri class in Dart? A) To perform HTTP requests B) To parse and manipulate Uniform Resource Identifiers C) To encode binary data as Base D) To represent file system paths only Answer: B Explanation: Uri provides parsing, building, and manipulation of URIs, handling encoding of query parameters, etc. Question 28. When using Dart FFI, which of the following is required to call a native C function? A) A dart:ffi DynamicLibrary instance loading the shared library B) Importing dart:io and using Process.start C) Declaring the function with @pragma('vm:entry-point') only D) Using dart:convert to serialize arguments Answer: A Explanation: DynamicLibrary loads the native library, and ffi provides Pointer and NativeFunction types to call C functions. Question 29. In Flutter, which platform channel type is used for sending a single request and receiving a single response? A) EventChannel
B) MethodChannel C) BasicMessageChannel D) BinaryChannel Answer: B Explanation: MethodChannel invokes a method on the platform side and receives a single result, fitting request‑response patterns. Question 30. Which annotation tells the Dart analyzer that a method overrides a superclass method? A) @override B) @Deprecated C) @required D) @protected Answer: A Explanation: @override signals that the method is intended to replace a superclass implementation, enabling analyzer checks. Question 31. Why is runtime reflection discouraged in Flutter applications? A) It is not supported on the web. B) It increases binary size and prevents tree‑shaking. C) It causes memory leaks. D) It disables null safety. Answer: B Explanation: Reflection (via dart:mirrors) prevents dead‑code elimination, leading to larger binaries; code generation tools are preferred. Question 32. Which of the following is a checked exception in Dart?
A) Returns a new iterable with transformed elements. B) Combines all elements into a single value using a provided function. C) Filters elements based on a predicate. D) Returns the first element that matches a condition. Answer: B Explanation: reduce iteratively applies a binary function to combine elements into a single accumulated result. Question 36. Which of the following is a correct way to declare a lazy‑initialized static field in a Dart class? A) static final List<int> _cache = []; B) static late List<int> _cache; C) static const List<int> _cache = []; D) static var _cache = []; Answer: B Explanation: static late defers initialization until the first access, allowing non‑nullable static fields to be set later. Question 37. In Dart, what does the ??= operator accomplish? A) Assigns a value only if the left‑hand side is null. B) Checks for equality and assigns if equal. C) Performs a null‑aware cascade. D) Combines two boolean expressions. Answer: A Explanation: The null‑aware assignment (??=) assigns the right‑hand expression to the left variable only when the left variable currently holds null.
Question 38. Which collection literal creates a map with integer keys and string values? A) {1: 'one', 2: 'two'} B) [1: 'one', 2: 'two'] C) {'1': 'one', '2': 'two'} D) Set(1, 'one') Answer: A Explanation: Curly braces with key‑value pairs denote a Map. The keys are integers, and the values are strings. Question 39. What is the effect of adding async to a function that already returns a Future? A) It changes the return type to Stream. B) It allows the use of await inside the function and automatically wraps the return value in a Future. C) It makes the function synchronous. D) It causes a compile‑time error. Answer: B Explanation: async enables await and ensures the function returns a Future, even if the body returns a plain value. Question 40. Which of the following correctly creates a broadcast Stream from a single‑subscription stream? A) stream.asBroadcastStream() B) stream.broadcast() C) Stream.broadcast(stream) D) Stream.fromIterable(stream) Answer: A
Answer: A Explanation: part declares a file as part of a library, while part of indicates the library it belongs to. Question 44. What does the @deprecated annotation indicate? A) The annotated element will be removed in the next major release. B) The element is experimental. C) The element should no longer be used; the analyzer will generate a warning. D) The element has been renamed. Answer: C Explanation: @deprecated marks APIs as obsolete; the analyzer warns developers when they use such members. Question 45. Which of the following is the correct way to annotate a class for code generation using json_serializable? A) @JsonSerializable() above the class definition. B) @Serializable() above the class definition. C) @JsonSerializable without parentheses. D) No annotation is needed; the generator works automatically. Answer: A Explanation: The json_serializable package requires the @JsonSerializable() annotation (with parentheses) on the class to trigger generation. Question 46. In a unit test using the test package, which function is used to define a group of related tests? A) group() B) suite()
C) testGroup() D) describe() Answer: A Explanation: group() allows you to organize tests under a common description and share setup/teardown code. Question 47. Which of the following is a best practice for naming a private library‑level variable? A) myVariable B) _myVariable C) my_variable D) MyVariable Answer: B Explanation: Prefixing with an underscore makes the identifier private to the library, following Dart’s naming conventions. Question 48. What does the --enable-asserts flag do when running a Dart VM? A) It disables all assert statements. B) It enables assert statements that are otherwise omitted in production mode. C) It turns on strong mode. D) It compiles the code to JavaScript. Answer: B Explanation: By default, asserts are stripped in production; the flag forces them to be evaluated during execution. Question 49. Which of the following statements about the Dart VM’s AOT compilation is correct?
Question 52. What does the ?? operator do in Dart? A) Returns the left operand if it is non‑null; otherwise returns the right operand. B) Performs a bitwise OR operation. C) Checks for equality with null. D) Forces a cast to nullable type. Answer: A Explanation: The null‑coalescing operator (??) provides a fallback value when the left side is null. Question 53. Which of the following is true about late final variables? A) They can be reassigned after the first assignment. B) They must be initialized at declaration. C) They are lazily initialized and cannot be reassigned once set. D) They are always nullable. Answer: C Explanation: late final defers initialization until first use and, being final, cannot be changed thereafter. Question 54. In a switch expression (available from Dart 3), what must each case return? A) Nothing; switch expressions are void. B) A value of the same type as the expression’s static type. C) A boolean indicating match success. D) A Future. Answer: B Explanation: A switch expression evaluates to a value; each case must produce a value compatible with the expected result type.
Question 55. Which of these statements about the for‑in loop is correct? A) It can iterate over any object that implements Iterator. B) It works only with List. C) It requires the iterable to implement Iterable<E>. D) It automatically modifies the collection during iteration. Answer: C Explanation: The for‑in construct works with any object that implements the Iterable<E> interface. Question 56. How do you declare a top‑level constant that is accessible across the entire package? A) final const myConst = 42; B) static const myConst = 42; C) const myConst = 42; D) var const myConst = 42; Answer: C Explanation: A top‑level const declaration is implicitly static and can be accessed throughout the package. Question 57. Which of the following is a correct way to create an immutable list literal? A) const [1, 2, 3] B) final [1, 2, 3] C) List.unmodifiable([1, 2, 3]) D) Both A and C Answer: D Explanation: Using const creates a compile‑time immutable list; List.unmodifiable creates a runtime immutable list. Both are valid.