Q.6 Which constructor will be called from the object created in the below C++ code?
class A
{
int i;
A()
{
i=0; cout<<i;
}
A(int x=0)
{
i=x; cout<<I;
};
}
A obj1
(A) Parameterized constructor
(B) Default constructor
(C) Run time error
(D) Compile time error
Q.8 In which access should a constructor be defined, so that object of the class can be
created in any function?
(A) Any access specifier will work
(B) Private
(C) Public
(C) Protected
Q.9 Which is most appropriate comment on following class definition?
class Student
{
int a;
public : float a;
};
(A) Error : same variable name can’t be used twice
(B) Error : Public must come first
(C) Error : data types are different for same variable
(D) It is correct
Q.10 Which class/set of classes can illustrate polymorphism in the following C++
code?
abstract class student
{
public : int marks;
calc_grade();
}
class topper:public student
{
public : calc_grade()
{
return 10;
}
};
class average:public student
{
public : calc_grade()
{
return 20;
}};
class failed{ int marks; };
(A) Only class student and topper together can show polymorphism
(B) Only class student can show polymorphism
(C) Class failed should also inherit class student for this code to work for
polymorphism
(D) All class student, topper and average together can show polymorphism