Constants – Exercises
Quiz Summary
0 of 10 Questions completed
Questions:
Information
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading…
You must sign in or sign up to start the quiz.
You must first complete the following:
Results
Results
0 of 10 Questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 point(s), (0)
Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)
Categories
- Not categorized 0%
-
Unfortunately, your results in the simulator were not up to the desired standards. 😔
However, take advantage of your unlimited access and continue to practice.
Remember, persistence and dedication will lead to mastery. 😎 -
Congratulations! 🎉
You have successfully passed the simulator and are now one step closer to achieving your certification.
We hope you will consider joining us again in your future certification journey.Wishing you the best of luck with the upcoming exam. Keep up the great work! 💪
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- Current
- Review
- Answered
- Correct
- Incorrect
-
Question 1 of 10
1. Question
Imagine you’re working on a Salesforce project for a car dealership. They have a specific interest rate that they use for car loans, and this rate does not change. To represent this constant rate, you want to declare a variable in Apex that will store the value
0.05(representing 5%) and ensure that its value cannot be modified anywhere else in the code.How should you declare this?
-
public class CarDealership {
Double INTEREST_RATE = 0.05;
}
CorrectIncorrect -
-
Question 2 of 10
2. Question
In a banking application, you’re trying to establish a minimum balance required for a new bank account. This value is always $100 and should remain unchanged in the system.
Declare this constant appropriately in the following code:
-
public class BankingApp {
Decimal MIN_BALANCE = 100;
}
CorrectIncorrect -
-
Question 3 of 10
3. Question
You’re designing an application that processes space missions. There’s a constant representing the speed of light in vacuum called
SPEED_OF_LIGHT_KM_PER_S, which is approximately299792kilometers per second.Declare this constant in an Apex class named
SpaceConstantsensuring that its value cannot be modified.-
public class SpaceConstants {
static SPEED_OF_LIGHT_KM_PER_S = ;
}
CorrectIncorrect -
-
Question 4 of 10
4. Question
You’re working on a billing application. For legal reasons, there’s a constant called
TAX_RATEthat represents the standard tax rate for all transactions, which is5%.Declare this constant in an Apex class named
BillingConstantsensuring its value cannot be changed after being initialized.-
public class BillingConstants {
static TAX_RATE = ;
}
CorrectIncorrect -
-
Question 5 of 10
5. Question
You’re creating a configuration for a payment gateway. Every transaction has a standard processing fee, which is $2.50. Also, the maximum transaction amount for a single purchase, determined by a method called
maxTransactionAmount(), needs to be stored as a constant.Declare these in an Apex class named “PaymentConfig”.
-
public class PaymentConfig {
static PROCESSING_FEE = ;
static MAX_TRANSACTION_AMOUNT;
public static Double maxTransactionAmount() {
return 5000.00;
}
{
MAX_TRANSACTION_AMOUNT = maxTransactionAmount();
}
}
CorrectIncorrect -
-
Question 6 of 10
6. Question
You’re creating a configuration for a gaming application. There’s a constant named
MAX_PLAYERSwhich indicates the maximum number of players allowed in a single game room, and this limit is 10. Additionally, the initial health each player gets when they start a game is calculated by a static method nameddefaultHealth().Declare these constants in an Apex class named
GameConfig.-
public class GameConfig {
static MAX_PLAYERS = ;
static STARTING_HEALTH;
public static Integer defaultHealth() {
return 100;
}
{
STARTING_HEALTH = defaultHealth();
}
}
CorrectIncorrect -
-
Question 7 of 10
7. Question
In a class that deals with car properties, you have a constant representing the number of wheels a standard car has, which is
4. You also have a method calleddefaultColor()which returns a standard color for cars in your application, and you want to store this value as a constant.Fill in the blanks:
-
public class CarProperties {
static WHEEL_COUNT = ;
static DEFAULT_COLOR;
public static String defaultColor() {
return “Blue”;
}
{
DEFAULT_COLOR = defaultColor();
}
}
CorrectIncorrect -
-
Question 8 of 10
8. Question
You’re writing a class that deals with the properties of a circle. You want to declare a constant for
PIwhich is approximately3.14159. Furthermore, you have a method nameddefaultRadius()that computes a standard radius value for the circles in your application, and you want to store this value as a constant.Complete the following class:
-
public class CircleProperties {
static PI = ;
static DEFAULT_RADIUS;
public static Double defaultRadius() {
return 5.5;
}
{
DEFAULT_RADIUS = defaultRadius();
}
}
CorrectIncorrect -
-
Question 9 of 10
9. Question
Consider a class that models attributes of an equilateral triangle. You wish to specify a constant that represents the number of sides an equilateral triangle has. Additionally, there’s a method called
defaultHeight()that calculates a standard height for these triangles in your system, and this value should be saved as a constant.Fill in the missing parts:
-
public class TriangleAttributes {
static SIDE_COUNT = ;
static DEFAULT_HEIGHT;
public static Double defaultHeight() {
return 8.7;
}
{
DEFAULT_HEIGHT = defaultHeight();
}
}
CorrectIncorrect -
-
Question 10 of 10
10. Question
Imagine you are working with a class that represents basic properties of a square. You want to define a constant that denotes the number of sides a square has. In addition, you have a method named
defaultLength()which computes a standard side length for the squares in your application, and you want this value stored as a constant.Complete the blanks in the following class:
-
public class SquareProperties {
static SIDE_COUNT = 4;
static DEFAULT_SIDE_LENGTH;
public static Double defaultLength() {
return 10.0;
}
{
DEFAULT_SIDE_LENGTH = defaultLength();
}
}
CorrectIncorrect -