Sobes.tech
Intern — Middle

Do you know what object-oriented programming is?

sobes.tech AI

Answer from AI

Object-oriented programming (OOP) is a programming paradigm based on the concept of objects, which contain data and methods to operate on that data. The main principles of OOP are:

  • Encapsulation — bundling data and methods that operate on that data within one object, hiding internal details.
  • Inheritance — creating new classes based on existing ones, inheriting their properties and methods.
  • Polymorphism — objects of different classes can respond to the same message (method call) in different ways.

Example in JavaScript (Node.js):

class Animal {
  constructor(name) {
    this.name = name;
  }
  speak() {
    console.log(`${this.name} makes a sound.`);
  }
}

class Dog extends Animal {
  speak() {
    console.log(`${this.name} says: Woof!`);
  }
}

const dog = new Dog('Sharik');
dog.speak(); // Sharik says: Woof!
Do you know what object-oriented programming is… - sobes.tech