Looking for ООП \ Програмування (JS) \ Вовкодав О.В. test answers and solutions? Browse our comprehensive collection of verified answers for ООП \ Програмування (JS) \ Вовкодав О.В. at elr.tnpu.edu.ua.
Get instant access to accurate answers and detailed explanations for your course questions. Our community-driven platform helps students succeed!
class Counter {constructor() {
this.count = 0;
}
increment() {
this.count++;
}
}
const c = new Counter();
c.increment();
c.increment();
console.log(c.count);
class Temperature {#celsius;
constructor(c) { this.#celsius = c; }
get fahrenheit() {
return this.#celsius \* 9/5 + 32;
}
set fahrenheit(f) {
this.#celsius = (f - 32) \* 5/9;
}
}
const t = new Temperature(0);
console.log(t.fahrenheit);
class AbstractShape {constructor() {
if (new.target === AbstractShape) {
throw new Error('Cannot instantiate abstract class');
}
}
area() {
throw new Error('Method area() must be implemented');
}
}
class Rectangle extends AbstractShape {
constructor(w, h) {
super();
this.w = w; this.h = h;
}
area() { return this.w \* this.h; }
}
const r = new Rectangle(4, 5);
console.log(r.area());
class BankAccount {#balance = 0;
deposit(amount) {
this.#balance += amount;
}
getBalance() {
return this.#balance;
}
}
const acc = new BankAccount();
acc.deposit(100);
console.log(acc.getBalance());
console.log(acc.#balance);
class MathUtils {static square(x) {
return x \* x;
}
}
console.log(MathUtils.square(4));
const m = new MathUtils();
console.log(m.square(4));
class Engine {start() { return 'Engine started'; }
}
class Car {
constructor() {
this.engine = new Engine();
}
drive() {
return this.engine.start() + ' - driving';
}
}
const car = new Car();
console.log(car.drive());
class Animal {speak() {
return 'Some sound';
}
}
class Dog extends Animal {
speak() {
return 'Woof!';
}
}
class Cat extends Animal {
speak() {
return 'Meow!';
}
}
const animals = [new Dog(), new Cat(), new Animal()];
animals.forEach(a =\> console.log(a.speak()));