You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+105Lines changed: 105 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -577,6 +577,111 @@ let car = new Car();
577
577
console.log(Car.prototype.isPrototypeOf(Car));
578
578
console.log(Car.prototype.isPrototypeOf(car));
579
579
```
580
+
### More Practice Questions (OOP)
581
+
**Question 1:** Guess the **Output** and Explain Why?
582
+
```js
583
+
functioncarObject(name, model) {
584
+
let car =Object.create(constructorObject);
585
+
car.name= name;
586
+
car.model= model;
587
+
this.engineMethod=function(){
588
+
console.log("This is engine method of car")
589
+
}
590
+
return car;
591
+
}
592
+
let constructorObject = {
593
+
speak:function(){
594
+
return"This is my car"
595
+
}
596
+
}
597
+
let myCar =carObject("Audi", 2023);
598
+
console.log(myCar.__proto__);
599
+
```
600
+
601
+
**Question 2:** You have given an example of **OOP** Code. Your task is to explain the use of **super** keyword in **Dogs** class.
602
+
And You have to **refactor** the code again after removing **super** keyword from the **Dogs** class(You have remove those lines/statements which are not **necessary** after **removing** super **keyword**)
603
+
604
+
```js
605
+
classAnimals {
606
+
constructor(name, age) {
607
+
this.name= name;
608
+
this.age= age;
609
+
}
610
+
sing() {
611
+
return`${this.name} can sing`;
612
+
}
613
+
dance() {
614
+
return`${this.name} can dance`;
615
+
}
616
+
}
617
+
classDogsextendsAnimals {
618
+
constructor(name, age, whiskerColor) {
619
+
super(name, age);
620
+
this.whiskerColor= whiskerColor;
621
+
}
622
+
whiskers() {
623
+
return`I have ${this.whiskerColor} whiskers`;
624
+
}
625
+
}
626
+
let newDog =newDogs("Clara", 33, "indigo");
627
+
console.log(newDog)
628
+
```
629
+
630
+
**Question 3:** What are the advantages of using **getter** and **setter** method in OOP?
631
+
632
+
**Question 4:** You have OOP code below. And there is **single** error in this code? Your task is to **remove that error**.
633
+
**Important Note**: To solve this error You need to know about **method chaining** concept.
634
+
```js
635
+
classCar {
636
+
constructor(id){
637
+
this.id= id;
638
+
}
639
+
setMake(make) {
640
+
this.make= make;
641
+
}
642
+
setModel(model) {
643
+
this.model= model
644
+
}
645
+
setFuelType(fuelType) {
646
+
this.fuelType= fuelType;
647
+
}
648
+
getCarInfo() {
649
+
return {
650
+
"id":this.id,
651
+
"make":this.make,
652
+
"model":this.model,
653
+
"fuelType":this.fuelType
654
+
};
655
+
}}
656
+
657
+
658
+
console.log(
659
+
newCar(233)
660
+
.setMake("Honda")
661
+
.setModel("Civic")
662
+
.setFuelType("Petrol")
663
+
.getCarInfo()
664
+
);
665
+
```
666
+
**Question 5:** What is difference between __ proto __ and prototype property of Object? Explain with **Example**?
667
+
668
+
669
+
**Question 6:** create class of **Person** with properties name, age.
670
+
Your main task is to add **static** method in that class of your choice ( e.g brainMethod)
0 commit comments