MCQs on Object-Oriented JavaScript (OOP) | JavaScript Advanced

Object-Oriented JavaScript (OOP) simplifies complex coding through its modular approach. Learn concepts like constructor functions, class syntax, prototypes, and inheritance with these 30 expertly curated multiple-choice questions (MCQs).


Constructor Functions (7 Questions)

  1. Which keyword is used to define a constructor function in JavaScript?
    a) constructor
    b) function
    c) class
    d) init
  2. What is the purpose of this in a constructor function?
    a) Refers to the global object
    b) Refers to the object being created
    c) Refers to a static method
    d) Refers to the parent class
  3. What happens if you call a constructor function without the new keyword?
    a) It throws an error
    b) The global object gets modified
    c) The object is created but this is undefined
    d) No action is performed
  4. In JavaScript, a constructor function typically starts with:
    a) a lowercase letter
    b) an uppercase letter
    c) a special character
    d) a number
  5. How can you verify an object is an instance of a constructor function?
    a) Using object.prototype.constructor
    b) Using object.constructor
    c) Using instanceof
    d) Using typeof
  6. What is returned implicitly by a constructor function if no return statement is provided?
    a) undefined
    b) The created object
    c) A string “constructor”
    d) Null
  7. Which of the following is NOT true about constructor functions?
    a) They can create multiple objects
    b) They always require the this keyword
    c) They replace the prototype
    d) They are reusable

Class Syntax and Class Inheritance (7 Questions)

  1. How do you define a class in JavaScript?
    a) class MyClass
    b) function class
    c) class = MyClass
    d) class.myClass
  2. Which method is used for creating and initializing an object in a class?
    a) init()
    b) constructor()
    c) create()
    d) initialize()
  3. How can a class inherit from another class in JavaScript?
    a) Using the extends keyword
    b) Using the inherit keyword
    c) Using the instanceof keyword
    d) Using the super keyword
  4. What does the super keyword do in a derived class?
    a) Calls the parent class’s constructor
    b) Creates a new object
    c) Binds the method to the child class
    d) Invokes a static method
  5. Can a class in JavaScript have multiple constructors?
    a) Yes, using overloading
    b) No, only one is allowed
    c) Yes, if static
    d) No, they are optional
  6. Which statement is true about methods in a class?
    a) They can be static or instance-specific
    b) They must be declared outside the class body
    c) They cannot access this
    d) They cannot be asynchronous
  7. How do you access a static method in JavaScript?
    a) Using an instance of the class
    b) Using the class name directly
    c) Using the super keyword
    d) Using this.methodName

Prototype and Prototype Chain (8 Questions)

  1. What is the purpose of the prototype property in JavaScript?
    a) To store instance-specific data
    b) To share methods among instances
    c) To override the global object
    d) To ensure encapsulation
  2. What is the default value of the prototype property in a constructor function?
    a) null
    b) An empty object
    c) Undefined
    d) A string
  3. What does the prototype chain represent?
    a) A sequence of parent classes
    b) A hierarchical structure for objects
    c) The inheritance of methods and properties
    d) A data storage method
  4. Which method is used to get the prototype of an object?
    a) Object.getPrototype()
    b) Object.getPrototypeOf()
    c) Object.prototype.get()
    d) Object.prototypeOf()
  5. What happens if a property is not found in an object?
    a) The script throws an error
    b) It checks the global object
    c) It searches up the prototype chain
    d) The method halts
  6. How can you add a method to an existing prototype?
    a) prototype.methodName
    b) object.prototype.methodName
    c) constructor.methodName
    d) object.addMethod()
  7. What is Object.prototype?
    a) The default prototype for objects
    b) A method for prototype linking
    c) A deprecated feature in ES6
    d) A static property
  8. Which method breaks the prototype chain?
    a) Object.create(null)
    b) Object.freeze()
    c) Object.definePrototype()
    d) Object.setPrototype()

Encapsulation, Inheritance, Polymorphism (8 Questions)

  1. What does encapsulation in JavaScript achieve?
    a) Hiding implementation details
    b) Creating static methods
    c) Extending the prototype chain
    d) Ensuring inheritance
  2. How can you make a property private in JavaScript?
    a) Use a # before the property name
    b) Use private keyword
    c) Use let
    d) Use static
  3. Inheritance allows:
    a) Methods to be overwritten
    b) Multiple constructors
    c) Prototype deletion
    d) Changing the data type of this
  4. What is polymorphism?
    a) Hiding data
    b) The ability of methods to take many forms
    c) A method to delete objects
    d) Linking multiple prototypes
  5. What keyword is used to override a method in a subclass?
    a) override
    b) super
    c) extends
    d) None; just redeclare the method
  6. What is the main benefit of polymorphism in OOP?
    a) Code reusability
    b) Data encapsulation
    c) Prototype chaining
    d) Dynamic typing
  7. Encapsulation prevents:
    a) Direct modification of private variables
    b) The use of inheritance
    c) Creating objects
    d) Dynamic method binding
  8. How do you access a private property in modern JavaScript?
    a) Using a method inside the class
    b) Directly using this.propertyName
    c) Using Object.getProperty()
    d) Using Object.prototype.property

Answers

QnoAnswer (Option with Text)
1b) function
2b) Refers to the object being created
3b) The global object gets modified
4b) an uppercase letter
5c) Using instanceof
6b) The created object
7c) They replace the prototype
8a) class MyClass
9b) constructor()
10a) Using the extends keyword
11a) Calls the parent class’s constructor
12b) No, only one is allowed
13a) They can be static or instance-specific
14b) Using the class name directly
15b) To share methods among instances
16b) An empty object
17c) The inheritance of methods and properties
18b) Object.getPrototypeOf()
19c) It searches up the prototype chain
20a) prototype.methodName
21a) The default prototype for objects
22a) Object.create(null)
23a) Hiding implementation details
24a) Use a # before the property name
25a) Methods to be overwritten
26b) The ability of methods to take many forms
27d) None; just redeclare the method
28a) Code reusability
29a) Direct modification of private variables
30a) Using a method inside the class

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top