Our website is made possible by displaying online advertisements to our visitors. Please consider supporting us by whitelisting our website.

» Object Oriented Programming (OOP) solved MCQs

Which of the following is true about new when compared with malloc. 1) new is an operator, malloc is a function 2) new calls constructor, malloc doesn’t 3) new returns appropriate pointer, malloc returns void * and pointer needs to typecast to appropriate type.

Question:

Which of the following is true about new when compared with malloc. 1) new is an operator, malloc is a function 2) new calls constructor, malloc doesn’t 3) new returns appropriate pointer, malloc returns void * and pointer needs to typecast to appropriate type.

A.

1 and 3

B.

2 and 3

C.

1 and 2

D.

all 1,2,3

Answer» c. 1 and 2

Note: The above multiple-choice question is for all general and Competitive Exams in India

Which of the following is true about new when compared with malloc. 1) new is an operator, malloc is a function 2) new calls constructor, malloc doesn’t 3) new returns appropriate pointer, malloc returns void * and pointer needs to typecast to appropriate type. Read More »

» Object Oriented Programming (OOP) solved MCQs

Which of the following is true about the following program#include class Test{public:int i;void get();};void Test::get(){std::cout i;}Test t; // Global object int main(){Test t; // local object t.get();std::cout

Question:

Which of the following is true about the following program
#include <iostream> class Test
{
public:
int i;
void get();
};
void Test::get()
{
std::cout <<“Enter the value of i: “; std::cin >>i;
}
Test t; // Global object int main()
{
Test t; // local object t.get();
std::cout <<“value of i in local t: “<<t.i<<‘\n’;
::t.get();
std::cout <<“value of i in global t: “<<::t.i<<‘\n’; return 0;
}

A.

compiler error: cannot have two objects with same class name

B.

compiler error in line “::t.get();”

C.

compiles and runs fine

Answer» c. compiles and runs fine

Note: The above multiple-choice question is for all general and Competitive Exams in India

Which of the following is true about the following program#include class Test{public:int i;void get();};void Test::get(){std::cout i;}Test t; // Global object int main(){Test t; // local object t.get();std::cout Read More »

» Object Oriented Programming (OOP) solved MCQs