Skip to content

Commit 5e70472

Browse files
Update README.md
Successfully Added 6 more Questions in OOP chapter.Thanks
1 parent f9c8b8c commit 5e70472

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed

README.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,111 @@ let car = new Car();
577577
console.log(Car.prototype.isPrototypeOf(Car));
578578
console.log(Car.prototype.isPrototypeOf(car));
579579
```
580+
### More Practice Questions (OOP)
581+
**Question 1:** Guess the **Output** and Explain Why?
582+
```js
583+
function carObject(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+
class Animals {
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+
class Dogs extends Animals {
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 = new Dogs("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+
class Car {
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+
new Car(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)
671+
672+
```js
673+
class Person {
674+
constructor(name,age){
675+
this.name = name;
676+
this.age = age;
677+
}
678+
}
679+
680+
let me = new Person("abhishek",25);
681+
console.log(me)
682+
683+
```
684+
580685
## Chapter 11( Async & Await )
581686

582687
### Assignments

0 commit comments

Comments
 (0)