This section covers the questions for Classes and Inheritance to clear all your concepts.
Question 1
What is the purpose of the constructor method in a class?
To define static properties of a class
To initialize object properties
To inherit methods from another class
To execute a class directly
Question 2
How do you define a static method in a class?
Using the static keyword
By defining the method inside the constructor
Using the classMethod keyword
By adding the method directly to the prototype
Question 3
Which keyword is used for inheritance in JavaScript classes?
inherit
extends
prototype
super
Question 4
What does the super keyword do?
Calls the parent class's constructor
Creates a new object in the class
Defines a static method
Overrides the parent class methods
Question 5
How do you define a private field in a class?
By using private keyword
By using _ before the field name
By using # before the field name
By declaring it inside the constructor
Question 6
Which of the following is an example of a Mixin?
A function that adds methods to a class
A class that extends another class
A method inside a static class
A constructor with parameters
Question 7
What will the following code log?
class Parent {
greet() {
return "Hello";
}
}
class Child extends Parent { }
const c = new Child();
console.log(c.greet());
Error
Hello
Undefined
Greet is not a function
Question 8
What is a key difference between a method and a static method?
Methods are bound to the instance, while static methods are bound to the class
Static methods are always private
Methods can only be defined inside the constructor
Static methods can only access private fields
Question 9
Which statement about inheritance is correct?
A class can extend multiple classes.
A class can extend only one class.
Inheritance is not possible in JavaScript.
A class must use super to inherit properties but not methods.
Question 10
Which of the following statements about private fields is true?
They are accessible by subclasses.
They can only be declared using the # syntax.
They can be accessed directly from outside the class.
They can only be used in static methods.
There are 10 questions to complete.