(Full Stack JavaScript) OOP Principles Knowledge Assessment Q & S 2024, Exams of Programming Languages

(Full Stack JavaScript) OOP Principles Knowledge Assessment Q & S 2024(Full Stack JavaScript) OOP Principles Knowledge Assessment Q & S 2024(Full Stack JavaScript) OOP Principles Knowledge Assessment Q & S 2024(Full Stack JavaScript) OOP Principles Knowledge Assessment Q & S 2024

Typology: Exams

2023/2024

Available from 07/05/2024

emilio-clemente-2
emilio-clemente-2 🇺🇸

2

(2)

356 documents

1 / 19

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Full Stack JavaScript
OOP Principles
Knowledge Assessment
Q & S
2024
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13

Partial preview of the text

Download (Full Stack JavaScript) OOP Principles Knowledge Assessment Q & S 2024 and more Exams Programming Languages in PDF only on Docsity!

Full Stack JavaScript

OOP Principles

Knowledge Assessment

Q & S

  1. Which of the following is NOT one of the four main principles of Object-Oriented Programming (OOP)? a. Encapsulation
    b. Polymorphism
    c. Inheritance
    d. Compilation

Answer: d. Compilation \

Rationale: Compilation is not a principle of OOP, whereas Encapsulation, Polymorphism, and Inheritance are.

  1. In JavaScript, what is the process of restricting direct access to some of an object's components called? a. Inheritance
    b. Encapsulation
    c. Abstraction
    d. Polymorphism

Answer: b. Encapsulation \

Rationale: Encapsulation is the concept where the internal details of an object are hidden, and access is restricted to its specific methods.

b. Observer
c. Factory
d. Strategy

Answer: a. Singleton \

Rationale: The Singleton pattern restricts instantiation of a class to one "single" instance.

Fill-in-the-Blank Questions

  1. The principle where a subclass inherits characteristics from a superclass is known as __________.

Answer: Inheritance \

Rationale: Inheritance allows a subclass to inherit properties and methods from its superclass.

  1. Polymorphism enables a mechanism to use a class exactly like its __________ class and yet each class keeps its own methods as they are.

Answer: Parent \

Rationale: Polymorphism allows methods to do different things based on the object it is acting upon, typically the parent class.

  1. In JavaScript, data hiding can be implemented using __________ closures.

Answer: Function \

Rationale: JavaScript closures can be used to create private variables and methods.

  1. The process of providing only essential information to the outside world and hiding the background details, is called __________.

Answer: Abstraction \

Rationale: Abstraction exposes only the necessary details to the user while hiding the implementation details.

  1. In OOP, __________ is the concept that a base or parent class reference can point to a child or derived class object.

Answer: Polymorphism \

Rationale: This concept is known as polymorphism, where a parent class reference can be used for objects of its subclasses.

True/False Questions

  1. True or False: In JavaScript, every function has a prototype property.

Rationale: JavaScript does support polymorphism. Although it employs prototype-based inheritance, it can still achieve polymorphic behavior.

  1. True or False: Abstraction in JavaScript is only achievable using abstract classes.

Answer: False \

Rationale: JavaScript does not natively support abstract classes, but abstraction can be achieved through other means, such as closures and factory functions.

Additional Case Study Questions (Mixed Formats)

  1. Which of the following is NOT a way to create an object in JavaScript? a. Object constructor
    b. Object.create()
    c. Literal notation
    d. Private constructor

Answer: d. Private constructor \

Rationale: JavaScript does not support private constructors directly as other languages like Java or C++ do.

  1. Fill in the blank: The __________ method in JavaScript can be used to copy all enumerable own properties from one or more source objects to a target object.

Answer: Object.assign \

Rationale: The Object.assign method is used for this purpose in JavaScript.

  1. True or False: JavaScript supports multiple inheritance.

Answer: False \

Rationale: JavaScript does not support multiple inheritance, but a similar effect can be achieved using mixins.

  1. In JavaScript, which of the following methods returns an array of a given object's own enumerable property names? a. Object.getOwnPropertyNames()
    b. Object.keys()
    c. Object.entries()
    d. All of the above

Answer: b. Object.keys() \

Rationale: Object.keys() returns an array of a given object's own enumerable property names.

  1. Fill-in-the-Blank: _________ refers to the concept in OOP where a subclass inherits the characteristics of a superclass.

Correct Answer: Inheritance

Rationale: Inheritance allows a class to inherit properties and behaviors from another class, promoting code reuse.

  1. Multiple Choice: What does the 'this' keyword represent in JavaScript OOP? a) The global object b) The current instance of the class c) The prototype object d) The function's execution context

Correct Answer: b) The current instance of the class

Rationale: In JavaScript OOP, 'this' refers to the current object the method or constructor is associated with.

  1. True/False: The concept of 'abstraction' in OOP is used to simplify complex reality by modeling classes appropriate to the problem.

Answer: True

Rationale: Abstraction simplifies the complex reality by modeling classes that are relevant to the problem, providing a more manageable set of features to work with.

  1. Fill-in-the-Blank: The design principle that suggests "prefer composition over _________" is aimed at promoting flexibility in OOP.

Correct Answer: inheritance

Rationale: Favoring composition over inheritance helps to design more flexible systems by composing behaviors at runtime.

  1. Multiple Choice: Which of the following is not a pillar of OOP? a) Encapsulation b) Polymorphism c) Inheritance d) Recursion

Correct Answer: d) Recursion

Rationale: Recursion is a programming technique, not a principle of OOP.

  1. True/False: JavaScript supports classical inheritance similar to languages like Java and C++.

Answer: False

Rationale: JavaScript implements prototypal inheritance, which differs from the classical inheritance model used in languages like Java and C++.

  1. Fill-in-the-Blank: The process by which one object acquires the properties of another object is known as _________.

Correct Answer: inheritance

  1. Multiple Choice: What is the term for an OOP feature that restricts access to certain components of an object? a) Encapsulation b) Abstraction c) Inheritance d) Polymorphism

Correct Answer: a) Encapsulation

Rationale: Encapsulation is the OOP feature that restricts access to certain parts of an object, protecting the object's internal state.

  1. True/False: The 'super' keyword in JavaScript is used to call functions on an object's parent class.

Answer: True

Rationale: The 'super' keyword is used within a subclass to call functions on the superclass.

  1. Fill-in-the-Blank: In OOP, _________ is the ability of different classes to be treated as instances of the same class through a common interface.

Correct Answer: Polymorphism

Rationale: Polymorphism allows different classes to be accessed through the same interface, highlighting the importance of interchangeable objects in OOP. Multiple Choice: Question: Which of the following best describes inheritance in OOP?

A) The process by which one class acquires the properties and behaviors of another class B) The process of hiding the complexities of a system by providing a simplified interface C) The ability of an object to take on multiple forms D) The process of creating multiple instances of a class

Correct Answer: A) The process by which one class acquires the

properties and behaviors of another class Rationale: Inheritance allows a class to inherit attributes and methods from another class, promoting code reusability and establishing a hierarchical relationship between classes. Fill-in-the-Blank: Question: Encapsulation in OOP refers to the bundling of data and methods that operate on the data into a single unit known as _.

Correct Answer: Object

Rationale: Encapsulation helps in data hiding and abstraction by restricting access to certain components of an object and promoting modularity in code design. True/False: Question: Polymorphism in OOP allows different objects to respond to the same message in different ways.

Correct Answer: True

Question: Encapsulation and data hiding are interchangeable terms in OOP.

Correct Answer: True

Rationale: Encapsulation involves bundling data and methods within a class to control access, while data hiding specifically refers to restricting access to certain data members within a class. Multiple Choice: Question: Which OOP principle promotes the ability of a single function to perform different actions based on the object calling it? A) Abstraction B) Inheritance C) Polymorphism D) Encapsulation

Correct Answer: C) Polymorphism

Rationale: Polymorphism enables the same function to exhibit different behaviors based on the object it is called upon, enhancing flexibility and extensibility in code design. Fill-in-the-Blank: Question: In OOP, the process of combining data and behavior in a single unit is known as _.

Correct Answer: Encapsulation

Rationale: Encapsulation helps in bundling data and methods within a class, promoting data security, code reusability, and modular design.

True/False: Question: An abstract class can be instantiated to create objects in Java.

Correct Answer: False

Rationale: Abstract classes cannot be instantiated, as they exist solely to provide a blueprint for other classes to extend and implement. Multiple Choice: Question: Which OOP principle emphasizes the ability to define common characteristics and behavior for a group of objects? A) Abstraction B) Inheritance C) Polymorphism D) Encapsulation

Correct Answer: B) Inheritance

Rationale: Inheritance allows classes to inherit attributes and methods from a superclass, facilitating code reuse and establishing a hierarchical structure. Fill-in-the-Blank: Question: In OOP, the process of creating a new object from an existing object is known as _.

Correct Answer: Cloning

Question: In OOP, the principle of code reusability is achieved through _.

Correct Answer: Inheritance

Rationale: Inheritance enables the reuse of code from a superclass in a subclass, promoting modularity and reducing redundancy in software development. True/False: Question: Interfaces in Java can contain method implementations.

Correct Answer: False

Rationale: Interfaces in Java define method signatures that must be implemented by classes but do not include method implementations, promoting loose coupling and flexibility in code design.