OOPs اسئلة واجوبة المقابلات
سؤال 21. Explain the term 'constructor chaining'.
Constructor chaining refers to the process of calling one constructor from another in the same class or a superclass. It allows for reusing code and initializing objects more efficiently.
Example:
class Vehicle {
constructor(make) {
this.make = make;
}
}
class Car extends Vehicle {
constructor(make, model) {
super(make);
this.model = model;
}
}
سؤال 22. What is the diamond problem in the context of multiple inheritance?
The diamond problem occurs when a class inherits from two classes that have a common ancestor. It can lead to ambiguity in the inheritance hierarchy, especially if the common ancestor has members.
سؤال 23. What is an interface in Java?
In Java, an interface is a collection of abstract methods. A class implements an interface, providing concrete implementations for all its methods. It allows for achieving multiple inheritance in Java.
Example:
interface Printable {
void print();
}
سؤال 24. What is the purpose of the 'final' keyword?
In OOP, the 'final' keyword can be applied to classes, methods, or variables. It indicates that a class cannot be extended, a method cannot be overridden, or a variable cannot be reassigned.
Example:
final class MyFinalClass {
// class content
}
سؤال 25. Explain the concept of method hiding.
Method hiding occurs when a subclass provides a static method with the same signature as a static method in its superclass. It does not override the method but hides it.
Example:
class Parent {
static show() {
console.log('Static method in Parent');
}
}
class Child extends Parent {
static show() {
console.log('Static method in Child');
}
}
الاكثر فائدة حسب تقييم المستخدمين: