C++ | Class and Object | Question 6
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; } |
chevron_right
filter_none
Contributed by Pravasi Meet
(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)
Explanation: The above program compiles & runs fine. Like variables it is possible to create 2 objects having same name & in different scope.
Quiz of this Question
Recommended Posts:
- C++ | Class and Object | Question 5
- C++ | Class and Object | Question 2
- C++ | Class and Object | Question 3
- C++ | Class and Object | Question 4
- C++ | Class and Object | Question 3
- Java | Class and Object | Question 4
- Java | Class and Object | Question 5
- Java | Class and Object | Question 2
- Java | Class and Object | Question 1
- Java | Class and Object | Question 4
- Java | Class and Object | Question 6
- Java | Class and Object | Question 7
- Object Slicing in C++
- Exception handling and object destruction | Set 1
- Where is an object stored if it is created inside a block in C++?



