Cyber Monday 2024! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

Salesforce Exam CRT-600 Topic 2 Question 68 Discussion

Actual exam question for Salesforce's CRT-600 exam
Question #: 68
Topic #: 2
[All CRT-600 Questions]

Refer to the following code:

class Vehicle{

constructor(plate){

this.plate = plate;

}

}

class Truck extends Vehicle{

constructor(plate, weight){

//Missing code

this.weight = weight;

}

displayWeight(){

console.log(`The truck ${this.plate} has a weight of ${this.weight}lb.`);

}

}let myTruck = new Truck('123Ab',5000);

myTruck.displayWeight();

Which statement should be added to missing code for the code to display 'The truck 123AB has a

weight of 5000lb.

Show Suggested Answer Hide Answer
Suggested Answer: A

Contribute your Thoughts:

Truman
6 months ago
Haha, I bet the answer is B. Trying to directly access the `plate` property of the parent class? Classic rookie mistake.
upvoted 0 times
Annabelle
5 months ago
Actually, I believe it's B) super.plate = plate
upvoted 0 times
...
Halina
6 months ago
No way, it has to be D) this.plate = plate
upvoted 0 times
...
Yan
6 months ago
I think it's A) super(plate)
upvoted 0 times
...
...
Dorsey
6 months ago
I'm stumped. Is it possible to get a hint? This question is driving me nuts!
upvoted 0 times
Loren
5 months ago
Oh, so the answer is A) super(plate)
upvoted 0 times
...
Annamae
6 months ago
You're welcome! Let me know if you need any more help.
upvoted 0 times
...
Simona
6 months ago
No, I haven't. I'll give it a shot. Thanks!
upvoted 0 times
...
Tiera
6 months ago
Yes, you need to call super(plate) in the Truck constructor to pass the plate parameter to the base class constructor.
upvoted 0 times
...
Lera
6 months ago
You need to call the constructor of the parent class in the child class constructor.
upvoted 0 times
...
Tiera
6 months ago
A) super(plate)
upvoted 0 times
...
Lavonda
6 months ago
User 2
upvoted 0 times
...
Rasheeda
6 months ago
User 1
upvoted 0 times
...
Avery
6 months ago
Have you tried using the 'super' keyword?
upvoted 0 times
...
...
Erick
7 months ago
Yeah, I agree with User 1. Calling super(plate) is a common practice in inheritance for constructors
upvoted 0 times
...
Shoshana
7 months ago
I see your point, but I think A) is the more conventional way to call the parent class constructor
upvoted 0 times
...
Dean
7 months ago
I'm pretty sure it's A. The `super()` call is needed to properly initialize the parent class properties.
upvoted 0 times
Larae
7 months ago
Yes, you are correct. The `super()` call is needed to properly initialize the parent class properties.
upvoted 0 times
...
Larae
7 months ago
A) super(plate)
upvoted 0 times
...
...
Jeanice
7 months ago
But wouldn't B) super.plate = plate also work since it directly assigns the plate value?
upvoted 0 times
...
Brock
7 months ago
Hmm, I think the answer is D. We need to use the `this` keyword to access the `plate` property in the `Truck` constructor since it's defined in the `Vehicle` class.
upvoted 0 times
Cortney
6 months ago
Hmm, I think the answer is D. We need to use the `this` keyword to access the `plate` property in the `Truck` constructor since it's defined in the `Vehicle` class.
upvoted 0 times
...
Latosha
6 months ago
A) super(plate)
upvoted 0 times
...
...
Erick
7 months ago
I agree, calling super(plate) in the Truck constructor will set the plate property from the Vehicle class
upvoted 0 times
...
Shoshana
7 months ago
I think the answer is A) super(plate)
upvoted 0 times
...
Ilene
8 months ago
Hah, good one! Yeah, those other options are pretty ridiculous. I'm glad we're all on the same page here. The `super(plate)` call is the key to making this work correctly.
upvoted 0 times
...
Reita
8 months ago
Alright, I'm convinced. Option A is the way to go. *chuckles* I wonder if the exam writers are trying to trip us up with those other options. They're like the equivalent of 'banana' as the answer to a math question.
upvoted 0 times
...
Bernardo
8 months ago
Yeah, that makes sense. The other options don't seem quite right. `super.plate = plate` wouldn't work because `super` doesn't have a `plate` property, and the other options are just trying to directly set the `plate` property, which wouldn't inherit it from the parent class.
upvoted 0 times
...
Ezekiel
8 months ago
I agree, option A seems to be the way to go. `super(plate)` will call the constructor of the parent class (`Vehicle`) and initialize the `plate` property.
upvoted 0 times
...
Rolland
8 months ago
Okay, let's think through this step-by-step. The `Truck` class extends the `Vehicle` class, which means it inherits the `plate` property. So, we need to call the `super` constructor to initialize the `plate` property.
upvoted 0 times
...
Beckie
8 months ago
Hmm, this is a tricky one. We need to understand the relationship between the `Vehicle` and `Truck` classes to answer this correctly. I'm leaning towards option A, but I'm not 100% sure.
upvoted 0 times
Aracelis
7 months ago
No, I believe it should be calling the constructor of the parent class with super(plate).
upvoted 0 times
...
Norah
7 months ago
But isn't option B setting the plate property correctly?
upvoted 0 times
...
Irene
7 months ago
I think option A is correct.
upvoted 0 times
...
...

Save Cancel