Given this:
struct { int x; } ix;
struct A { A() {}; int x; };
A ia;
Which of these is true?
a. ix is an object
b. ia is an object
c. both are objects
d. both are not objects.
Answer is "An object is an instance of a class"
Explanation: An object is instance of its class. It can be declared in the same way that a variable is declared, only thing is you have to use class name as the data type.
Answer is "All of the mentioned"
The correct answer is E.Classes provide the blueprint of objects to be created while interfaces provide contracts for the classes implementing them.
Many of these answers have ignored the C++ tag. In C++, "an object is a region of storage. [Note: a function is not an object, regardless of whether or not it occupies storage in the same way that objects do.]" (The C++ Standard, 1.8/1).
If the homework question is about C++, then no other definition of object is applicable, not even "anything that is visible or tangible and is relatively stable in form" (dictionary.reference.com). It's not asking for your opinion about OOP principles, it's in effect asking whether ix and ia are variables.
Since it's homework I'll not tell you the answer, but do note that struct { int x; } ix;
is not the same thing as struct ix { int x; };
.
On the other hand, if the homework assignment is about OOP principles, then knock yourself out with whatever definition your lecturer has given you of "object". Since I don't know what that is, I can't tell you what answer he'll consider correct...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With