yoklainterview sim

Mobile Fl Dart Language Null Safety Interview Questions

75 verified Mobile Fl Dart Language Null Safety interview questions — solve with answers, learn from explanations, test yourself in a real simulation.

Try the real simulation →

Sample questions

Fl Dart Language Null SafetyDifficulty 1
In Dart's sound null safety, what does appending ? to a type like String? mean?
  • aThe variable is nullable only inside async functions.
  • bThe variable is optional and can be omitted entirely from the class.
  • cThe variable can hold either a String value or null.
  • dThe variable must be assigned before the constructor body runs.
Explanation:A ? suffix on a type marks it nullable; without it (e.g. String), the compiler guarantees the variable can never hold null, and this is enforced at compile time.
Fl Dart Language Null SafetyDifficulty 1
String? name;
print(name?.length);

What happens when name is null?
  • aIt prints 0, since length defaults to zero for null strings.
  • bThe program fails to compile because length isn't defined on null.
  • cA NoSuchMethodError is thrown at runtime.
  • dnull is printed, no exception is thrown.
Explanation:The ?. operator short-circuits: if the receiver is null, the whole expression evaluates to null instead of invoking the member, so no error occurs.
Fl Dart Language Null SafetyDifficulty 1
int? maybeCount;
int count = maybeCount ?? 0;

What does the ?? operator do here?
  • aIt throws an exception if maybeCount is not null.
  • bIt assigns 0 to count if maybeCount is null, otherwise the value of maybeCount.
  • cIt compares maybeCount to 0 and returns a boolean.
  • dIt only works when both operands are the exact same nullable type.
Explanation:?? is the null-coalescing operator: it evaluates the left side, and if that is null, falls back to the right-side expression.
Fl Dart Language Null SafetyDifficulty 2
String? name;
print(name!.length);

What happens when name is null?
  • aIt silently returns 0 for length.
  • bA runtime exception is thrown because ! asserted non-null but the value is null.
  • cIt compiles to a no-op and prints nothing.
  • dThe compiler rejects this code before it can run.
Explanation:The ! (bang) operator tells the compiler "trust me, this is non-null" and casts away nullability at compile time; if the value is actually null at runtime, it throws a TypeError/null-check exception.
Fl Dart Language Null SafetyDifficulty 2
What is the purpose of the late keyword on a non-nullable field like late String name;?
  • aIt makes the field nullable so it can be left unassigned safely.
  • bIt marks the field as computed lazily only inside const constructors.
  • cIt defers the non-null check to first-use time instead of declaration/constructor time.
  • dIt forces the field to be re-evaluated every time it is read.
Explanation:late lets a variable be non-nullable while its initialization happens later (e.g. set in initState); the compiler trusts that it will be assigned before first read, and throws a LateInitializationError at runtime if that trust is broken.
Fl Dart Language Null SafetyDifficulty 1
Why does marking a named constructor parameter required matter in a class with nullable fields?
  • aIt is only valid on positional parameters, not named ones.
  • bIt automatically makes the parameter's type non-nullable regardless of its declared type.
  • cIt only affects documentation/IDE hints and has no compile-time effect.
  • dIt forces callers to pass the argument, even if otherwise optional as named.
Explanation:required is orthogonal to nullability: a named parameter can be required and still nullable (required int? x), or optional and non-nullable (with a default). required only enforces that the call site supplies the argument.

Test yourself against the 2400-question Mobile bank.

Start interview