CARVIEW |
Object-Oriented-Programming(OOPS)
Object-Oriented-Programming(OOPS)
Question 1
What is the purpose of the constructor() method in a JavaScript class?
To define class methods
To initialize properties when an object is created
To handle inheritance
To call the parent class constructor
Question 2
Which of the following is used to declare a class in JavaScript?
function ClassName {}
class ClassName {}
var ClassName = {}
object ClassName {}
Question 3
What is the output of the following code?
class Person {
constructor(name) { this.name = name; }
greet() { console.log(`Hi, I am ${this.name}`); }
}
new Person('Alice').greet();
Hi, I am Alice
Hello, Alice
Hi
undefined
Question 4
What is inheritance in JavaScript?
Sharing methods between classes
Adding methods to an existing class
Extending functionality of another class
Making methods private
Question 5
What will the following code output?
class Animal {
speak() { console.log("Animal speaks"); }
}
class Dog extends Animal {
speak() { console.log("Dog barks"); }
}
new Dog().speak();
Animal speaks
Dog barks
undefined
Error
Question 6
What keyword is used to call the constructor of the parent class?
this()
super()
parent()
base()
Question 7
Which of the following is NOT a feature of JavaScript classes?
Encapsulation
Inheritance
Function Overloading
Constructor Method
Question 8
What is the output of the following code?
class Student {
constructor(name, grade) { this.name = name; this.grade = grade; }
intro() { console.log(`I'm ${this.name} in grade ${this.grade}`); }
}
new Student('Mike', 10).intro();
I'm Mike in grade 10
undefined
I'm Mike
Mike in grade 10
Question 9
What is Abstraction?
Hiding complexity, showing only essential parts
Creating multiple objects
Inheriting properties
Encapsulating data
Question 10
What concept is demonstrated in this code?
class Vehicle {
drive() { console.log('Driving vehicle'); }
}
class Car extends Vehicle {
drive() { console.log('Driving car'); }
}
Abstraction
Polymorphism
Encapsulation
Inheritance
There are 10 questions to complete.