Quiz on Interfaces in C++
C++ interfaces define how a class is supposed to behave without requiring any specific implementation. Objects and classes in C++ provide this functionality as a supplement. Let’s take a quick quiz for understanding more about Interfaces in C++. Have a Good learning experience!
0 of 15 Questions completed Questions: You have already completed the quiz before. Hence you can not start it again. Quiz is loading… You must sign in or sign up to start the quiz. You must first complete the following: 0 of 15 Questions answered correctly Your time: Time has elapsed You have reached 0 of 0 point(s), (0) Earned Point(s): 0 of 0, (0) C++ interfaces are implemented using which of the following methods? C++’s interface is similar to what? In the client mode, what is imported? What is the output of the following code snippet? What is the output of the following code snippet? What is the output of the following code snippet? What is the output of the following code snippet? What is the output of the following code snippet? What is the output of the following program? What is the output of the following program? What is the output of the following code snippet? What is the output of the following code snippet? What is the output of the following code snippet? What is the output of the following code? What is the output of the following program? Quiz Summary
Information
Results
Results
0 Essay(s) Pending (Possible Point(s): 0) Categories
1. Question
2. Question
3. Question
4. Question
#include <iostream>
using namespace std;
struct University{
virtual void course() = 0;
};
struct Student : University {
virtual void course() {
cout<<“Student”;
}
};
University& i(University&);
int main() {
University* univ;
Student stu;
static_cast<University>(stu);
} 5. Question
#include <iostream>
using namespace std;
class Shape
{
public:
virtual void drawShape()=0;
};
class Square:Shape
{
public:
void drawShape()
{
cout<<“Drawing a Square!”<<endl;
}
};
class Rect:Shape
{
public:
void drawShape()
{
cout<<“Drawing a Rectangle!”<<endl;
}
};
int main()
{
Square s;
Rect r;
cout<<“QuizOrbit C++ Interfaces!”<<endl;
s.drawShape();
r.drawShape();
return 0;
} 6. Question
#include <iostream>
using namespace std;
class University{
virtual void course() = 0;
};
class Student : University {
void courseFee() {
cout<<“Student Course Fee”;
}
};
int main() {
Student stu;
} 7. Question
#include <iostream>
using namespace std;
class Animal
{
public:
virtual void name()=0;
};
class Dog:Animal
{
public:
void name()
{
cout<<“Dog name is Baby!”<<endl;
}
};
class Cat:Animal
{
public:
void name()
{
cout<<“Cat name is catty!”<<endl;
}
};
int main()
{
Cat c;
Dog d;
cout<<“QuizOrbit C++ Interfaces!”<<endl;
c.name();
d.name();
return 0;
} 8. Question
#include <iostream>
using namespace std;
class Animal
{
public:
virtual void name()=0;
void play(){
cout<<“Pet is Playing “<<endl;
}
};
class Dog:public Animal
{
public:
void name()
{
cout<<“Dog name is Baby!”<<endl;
}
};
class Cat:public Animal
{
public:
void name()
{
cout<<“Cat name is catty!”<<endl;
}
};
int main()
{
Cat c;
Dog d;
cout<<“QuizOrbit C++ Interfaces!”<<endl;
c.name();
d.name();
c.play();
d.play();
return 0;
} 9. Question
#include <iostream>
using namespace std;
class Animal
{
public:
virtual void name()=0;
void play(){
cout<<“Pet is Playing “<<endl;
}
};
class Dog: Animal
{
public:
void name()
{
cout<<“Dog name is Baby!”<<endl;
}
};
class Cat: Animal
{
public:
void name()
{
cout<<“Cat name is catty!”<<endl;
}
};
int main()
{
Cat c;
Dog d;
cout<<“QuizOrbit C++ Interfaces!”<<endl;
c.name();
d.name();
c.play();
d.play();
return 0;
} 10. Question
#include <iostream>
using namespace std;
class Animal
{
public:
virtual void name()=0;
void play(){
cout<<“Pet is Playing “<<endl;
}
};
class Dog:public Animal
{
public:
void name()
{
cout<<“Dog name is Baby!”<<endl;
}
};
class Cat:public Animal
{
public:
void name()
{
cout<<“Cat name is catty!”<<endl;
}
};
int main()
{
Animal *obj = new Dog();
obj->name();
Animal *obj1=new Cat();
obj1->play();
cout<<“QuizOrbit C++ Interfaces!”<<endl;
return 0;
} 11. Question
#include <iostream>
using namespace std;
class Animal
{
public:
virtual void name()=0;
void play(){
cout<<“Pet is Playing “<<endl;
}
};
class Dog:Animal
{
public:
void name()
{
cout<<“Dog name is Baby!”<<endl;
}
};
class Cat:Animal
{
public:
void name()
{
cout<<“Cat name is catty!”<<endl;
}
};
int main()
{
Animal *obj = new Dog();
obj->name();
Animal *obj1=new Cat();
obj1->play();
cout<<“QuizOrbit C++ Interfaces!”<<endl;
return 0;
} 12. Question
#include <iostream>
using namespace std;
class Parent
{
public:
virtual void name()=0;
void play(){
cout<<“Class is Playing a game “<<endl;
}
};
class Derived:public Parent
{
public:
void name()
{
cout<<“Derived class executed!”<<endl;
}
};
class Cat:public Parent
{
public:
void name()
{
cout<<“Derived2 class is executing!”<<endl;
}
};
int main()
{
Parent *obj = new Derived();
obj->name();
Parent *obj1=new Derived();
obj1->play();
cout<<“QuizOrbit C++ Interfaces!”<<endl;
return 0;
} 13. Question
#include<iostream>
using namespace std;
class Parent
{
public:
virtual void display() = 0;
};
class Child: public Parent
{
public:
void display() { cout << “In Child Class \n”; }
};
int main(void)
{
Parent *pt = new Child();
pt->display();
return 0;
} 14. Question
#include<iostream>
using namespace std;
class Parent
{
protected:
int a;
public:
virtual void func() = 0;
Parent(int c) {
a = c;
cout<<“Parent class constructor called\n”;
}
};
class Child: public Parent
{
int b;
public:
Child(int c, int d):Parent(c) { b = d; }
void func() { cout << “a = ” << a << “, b = ” << b<<‘\n’; }
};
int main(void)
{
Child c(5, 8);
c.func();
Parent *pb=new Child(8,9);
pb->func();
return 0;
} 15. Question
#include<iostream>
using namespace std;
class University{
public:
virtual void course() = 0;
void classes() {
cout<<“Classes”;
}
};
class Faculty: public University{
public:
void course() {
cout<<“select any course from no. of available courses:”<<endl;
}
};
int main(){
Faculty fc;
fc.course();
fc.classes();
return 0;
}
Summary
Classes and objects are closely related to interfaces. The notion of interfaces and abstract classes is more or less the same, the two terms referring to a similar concept.