Expert
What will the following pseudo-code display?
class A
{
public function foobar() {
echo this->foo();
echo this->bar();
}
private function foo() {
return "A::foo\\n";
}
public function bar() {
echo "A::bar\\n";
}
}
class B extends A
{
private function foo() {
return "B::foo\\n";
}
public function bar() {
echo "B::bar\\n";
}
}
var toto = new B();
toto->foobar();
Author: Eric HostaleryStatus: PublishedQuestion passed 1343 times
Edit
0
Community Evaluations
Najmul
01/10/2023
The provided pseudo-code contains some syntax errors, such as the use of 'this' instead of '$this' to refer to object properties and methods.
In this code, class B overrides the foo() method while extending class A, and it also overrides the bar() method. When you create an instance of class B and call its foobar() method, it calls the overridden foo() and bar() methods from class B.
I think the answer is:
B::foo
B::bar
Similar QuestionsMore questions about OOP
13
Is the following code valid?
class Person {
constructor(name, age) {
this.name = name;
this.age = age;
}
}
const person = new Person('John', 20);
console.log(person.name);
console.log(person.age);8
You need to develop a class for which there should be only one instance throughout your application. Which design pattern should you use for this?7
Can we extend an abstract class in Java?4
Is the following code valid?
class Person {
constructor(name, age) {
this.name = name;
this.age = age;
}
}
const person = new Person('John', 20);
console.log(person.name);
console.log(person.age);3
Can an interface inherit from another interface?