Which of the following is not a principle of Object-Oriented Programming (OOP)?
Which keyword is used to create an object in C++?
1 Crore+ students have signed up on EduRev. Have you? Download the App |
What is the purpose of a constructor in C++?
Which access specifier allows the members of a class to be accessible from any other class?
What will be the output of the following code?
#include <iostream>
class MyClass {
public:
int x;
void display() {
std::cout << "x = " << x << std::endl;
}
};
int main() {
MyClass obj;
obj.x = 5;
obj.display();
return 0;
}
What will be the output of the following code?
#include <iostream>
class Base {
public:
void show() {
std::cout << "Base class" << std::endl;
}
};
class Derived : public Base {
public:
void show() {
std::cout << "Derived class" << std::endl;
}
};
int main() {
Derived d;
Base* ptr = &d;
ptr->show();
return 0;
}
What will be the output of the following code?
#include <iostream>
class Base {
public:
virtual void show() {
std::cout << "Base class" << std::endl;
}
};
class Derived : public Base {
public:
void show() {
std::cout << "Derived class" << std::endl;
}
};
int main() {
Derived d;
Base* ptr = &d;
ptr->show();
return 0;
}
What will be the output of the following code?
#include <iostream>
class Base {
public:
virtual void show() {
std::cout << "Base class" << std::endl;
}
};
class Derived : public Base {
public:
void show() {
std::cout << "Derived class" << std::endl;
}
};
int main() {
Derived d;
Derived* ptr = &d;
Base* bptr = ptr;
bptr->show();
return 0;
}
What will be the output of the following code?
#include <iostream>
class Base {
public:
int x;
Base() {
x = 0;
}
virtual void display() {
std::cout << "x = " << x << std::endl;
}
};
class Derived : public Base {
public:
Derived() {
x = 5;
}
void display() {
std::cout << "x = " << x << std::endl;
}
};
int main() {
Base* bptr = new Derived();
bptr->display();
delete bptr;
return 0;
}
Which type of inheritance is illustrated in the following code?
class A {
public:
void foo() {
std::cout << "A" << std::endl;
}
};
class B : public A {
public:
void foo() {
std::cout << "B" << std::endl;
}
};
int main() {
B b;
b.foo();
return 0;
}
Which statement is true about function overriding in C++?
What is the output of the following code?
#include <iostream>
class A {
public:
virtual void foo() {
std::cout << "A" << std::endl;
}
};
class B : public A {
public:
void foo() {
std::cout << "B" << std::endl;
}
};
int main() {
A* ptr = new B();
B* bptr = dynamic_cast<B*>(ptr);
bptr->foo();
return 0;
}
Which statement is true about pure virtual functions in C++?
Which concept is illustrated in the following code?
class Base {
public:
virtual void foo() = 0;
};
class Derived : public Base {
public:
void foo() {
std::cout << "Derived" << std::endl;
}
};
int main() {
Base* ptr = new Derived();
ptr->foo();
return 0;
}