C# Programming - Classes and Objects - Discussion

Discussion Forum : Classes and Objects - General Questions (Q.No. 16)
16.
Which of the following statements is correct about classes and objects in C#.NET?
Class is a value type.
Since objects are typically big in size, they are created on the stack.
Objects of smaller size are created on the heap.
Smaller objects that get created on the stack can be given names.
Objects are always nameless.
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
9 comments Page 1 of 1.

Ahmed Ramadan said:   10 years ago
Point P = new Point();

In this case, there is two things have been created.

1- Pointer named P in the Stack.

2- Object in the heap.

Here Object has no name, However, when you create an object and give it a name you give the pointer that name not the object itself. So that objects are nameless as the answer says.

Alek said:   1 decade ago
This is dubious at least. Objects can be named and created on the stack if they are value-types. Only instances of reference types are always nameless. Value-types are objects but they are not reference types, because they ultimately inherit from system object (which is an object). Inheritance is a relation, so value-types is a object.

Rj Raja said:   1 decade ago
new sample();

When the above statement is executed then it satisfies all the rules of object creation and also it's a nameless object

Anjali said:   1 decade ago
It is completely wrong to say that object are always nameless,
For one time use we make object anonymous but not always.

Andrue Cope said:   1 decade ago
In the sense that objects are reference counted I suppose 'E' is correct but it's a sightly odd way of putting it. By that I mean that in this example:

wibble a = new wibble();
wibble b = new wibble();

We have two nameless objects on the heap and two variables 'a' and 'b' that point them. Generally an irrelevant distinction but not if we add:

wibble c=a;

Now we have a third variable but still only two objects.

VigneshG said:   1 decade ago
Option E applies only because all the other options are incorrect. Objects can be named or nameless.

Anvesh Mika said:   1 decade ago
Object can be nameless or named. Objects need not compulsory a nameless object, if we don't declare object name in the expression then nameless object gets created automatically or else a named object.

Sindujadevi said:   1 decade ago
For example:

class sample
{
}
class test
{
//creating object for sample
sample ob=new sample();
}

Then tell me what is obj, its name of the class only right?

BK Mishra said:   1 decade ago
String str1="Some Value";

String str2="Some Value";

Now compare both: str1.Equals(str2) // Here Both the Objects have name str1 and str2, But

str1.Equals("Some Value"); // Here the second string is anonymous object or nameless object.

My view is Object can be nameless but not always.

Post your comments here:

Your comments will be displayed after verification.