Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which of these statements about objects is true?

Tags:

c++

object

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.
like image 789
Murali Avatar asked Jan 20 '10 01:01

Murali


People also ask

Which statement is true about object?

Answer is "An object is an instance of a class"

Which of the following is true about object 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.

Which of following statements about objects in C is correct?

Answer is "All of the mentioned"

Which one of the following statements is true of classes and objects in Java?

The correct answer is E.Classes provide the blueprint of objects to be created while interfaces provide contracts for the classes implementing them.


1 Answers

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...

like image 54
Steve Jessop Avatar answered Nov 07 '22 08:11

Steve Jessop