Vispro Week 1 - OOP concept in DART

Quiz
•
Computers
•
University
•
Medium
Kasmir Syariati
Used 1+ times
FREE Resource
33 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is DART?
programming language
programming framework
programming architecture
programming paradigm ✅
2.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What will be the type of x in the following Dart code?
dynamic
int
Object
num
Answer explanation
When declared with var, Dart infers the type from the first assignment. Here, x becomes int. If you want it to be truly dynamic, you must explicitly declare dynamic.
3.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Which of the following correctly explains the difference between final and const in Dart?
final can be set only once at runtime, const is a compile-time constant
const can be reassigned, final cannot
Both are identical
final must always be declared with a value, const does not
Answer explanation
final is initialized once and can hold a runtime value. const must be assigned a compile-time constant.
4.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What will this Dart code print?
null
Guest
Compilation error
Empty string
Answer explanation
Since name is nullable and currently null, the null-coalescing operator ?? provides "Guest" as the fallback.
5.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Which scenario is the best use case for the late keyword in Dart?
When you want to delay initialization of a non-nullable variable
When you want to make a variable nullable
When you want a compile-time constant
When you want to create a global variable
Answer explanation
late is used when a non-nullable variable cannot be initialized immediately, but you guarantee it will be set before use.
The late keyword in Dart is used to declare a variable or field that will be initialized at a later time, specifically when it is first accessed. This keyword is particularly useful in the context of Dart's sound null safety, as it allows for the declaration of non-nullable variables without requiring immediate initialization.
The primary use case for late is to declare non-nullable variables that cannot be initialized at the point of declaration. Without late, such variables would either need to be marked as nullable (using ?) or initialized immediately, which might not always be feasible.
6.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What will this Dart code print?
42
"hello"
Compilation error
dynamic
Answer explanation
A dynamic variable can change its type at runtime. Initially it is an int, then reassigned to a String.
In Dart, the dynamic keyword allows for the declaration of a variable whose type can change at runtime. This means a variable declared with dynamic can hold values of any type, and its type can be reassigned throughout its lifecycle.
Runtime Type Flexibility:
Unlike var (which infers a type at compile-time and then restricts the variable to that type), dynamic truly allows the type to change during program execution.
Reduced Type Safety:
While offering flexibility, using dynamic sacrifices compile-time type checking. This means potential type-related errors might only be discovered at runtime, leading to less robust code compared to using specific types or var with type inference.
Use Cases:
dynamic is typically used when the exact type of a variable is genuinely unknown or when interoperating with external systems (like JSON parsing) where the data structure might be unpredictable.
Best Practice:
In general, it is recommended to use dynamic sparingly and only when necessary due to the reduced type safety. Prefer specific types or var with type inference for better code maintainability and error prevention.
7.
MULTIPLE CHOICE QUESTION
30 sec • 2 pts
What is the purpose of extension methods in Dart?
To allow adding new methods to existing classes without modifying them
To create subclasses dynamically
To override private methods
To replace inheritance
Answer explanation
Extension methods in Dart allow developers to add new functionalities to existing classes without modifying their original source code or using inheritance. This feature is particularly useful for extending the behavior of classes from core libraries or third-party packages that cannot be directly altered.
Extension methods enable the addition of methods, getters, setters, and operators to a class as if they were part of its original definition.
Create a free account and access millions of resources
Similar Resources on Wayground
34 questions
Прога 3

Quiz
•
University
30 questions
Comp 4 - Midterm Quiz 1

Quiz
•
University
33 questions
Pre assessment_Front end_Athani

Quiz
•
University
33 questions
Pre assessment_Front end_Ranebennur

Quiz
•
University
33 questions
Pre assessment quiz_ Front end + react_ Khanapur

Quiz
•
University
30 questions
Mastering OOPs in Python

Quiz
•
University
30 questions
Intro to OOP

Quiz
•
University
30 questions
Java Programming Challenge

Quiz
•
University
Popular Resources on Wayground
20 questions
Brand Labels

Quiz
•
5th - 12th Grade
10 questions
Ice Breaker Trivia: Food from Around the World

Quiz
•
3rd - 12th Grade
25 questions
Multiplication Facts

Quiz
•
5th Grade
20 questions
ELA Advisory Review

Quiz
•
7th Grade
15 questions
Subtracting Integers

Quiz
•
7th Grade
22 questions
Adding Integers

Quiz
•
6th Grade
10 questions
Multiplication and Division Unknowns

Quiz
•
3rd Grade
10 questions
Exploring Digital Citizenship Essentials

Interactive video
•
6th - 10th Grade
Discover more resources for Computers
11 questions
NFL Football logos

Quiz
•
KG - Professional Dev...
20 questions
Definite and Indefinite Articles in Spanish (Avancemos)

Quiz
•
8th Grade - University
7 questions
Force and Motion

Interactive video
•
4th Grade - University
36 questions
Unit 5 Key Terms

Quiz
•
11th Grade - University
38 questions
Unit 6 Key Terms

Quiz
•
11th Grade - University
20 questions
La Hora

Quiz
•
9th Grade - University
7 questions
Cell Transport

Interactive video
•
11th Grade - University
7 questions
What Is Narrative Writing?

Interactive video
•
4th Grade - University