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
How do you define a static method in a class?
By defining the method inside the constructor
Using the classMethod keyword
By adding the method directly to the prototype
Which keyword is used for inheritance in JavaScript classes?
What does the super keyword do?
Calls the parent class's constructor
Creates a new object in the class
Overrides the parent class methods
How do you define a private field in a class?
By using _ before the field name
By using # before the field name
By declaring it inside the constructor
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
What will the following code log?
JavaScript
class Parent {
greet () {
return "Hello" ;
}
}
class Child extends Parent { }
const c = new Child ();
console . log ( c . greet ());
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
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.
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.
Ready to go from coding beginner to development pro? Our DSA to Development Coding Guide has everything you need to crush coding interviews and ace real-world projects! Limited spots available!Enroll Now and Transform Your Coding Skills! Also get 90% fee refund on completing 90% of the course in 90 days ! Take the Three 90 Challenge today.
There are 10 questions to complete.
Take a part in the ongoing discussion View All Discussion