C# Programming - Classes and Objects - Discussion
Discussion Forum : Classes and Objects - General Questions (Q.No. 10)
10.
Which of the following statements are correct about the C#.NET code snippet given below?
sample c;
c = new sample();
- It will create an object called sample.
- It will create a nameless object of the type sample.
- It will create an object of the type sample on the stack.
- It will create a reference c on the stack and an object of the type sample on the heap.
- It will create an object of the type sample either on the heap or on the stack depending on the size of the object.
Discussion:
11 comments Page 1 of 2.
Aarti said:
1 decade ago
How come 'nameless' object is created when we have named object as 'c'?
(2)
Johan Braanen said:
1 decade ago
Both 2 and 4 are wrong.
2: The name of the object is "c"
4: We don't know if the objects is placed on the heap, because we don't know If it is a reference type or a value type.
2: The name of the object is "c"
4: We don't know if the objects is placed on the heap, because we don't know If it is a reference type or a value type.
(1)
Pooja said:
1 decade ago
Why we say object of the type sample on heap ?
Silky Malik said:
1 decade ago
@pooja objects' contents are always created on heap and its reference on stack.
Gopesh said:
1 decade ago
Why it is saying nameless object, since name of the object is 'c' only ?
Sindujadevi said:
1 decade ago
We are creating object to class so I think this is the reference type and it will store in heap.
Taylor said:
1 decade ago
I agree with Silky, but just wonder why they say it's a nameless object?
Taylor said:
1 decade ago
I agree with Silky, but just wonder why they say it's a nameless object?
Nicholas Mahbouby said:
1 decade ago
I agree with @Johan.
The name of the object is C. Only for reference types does the CLR create a nameless object on the heap and a named value type that contains it's address. From the code snippet it is not possible to tell if the type "sample" is a reference type or a value type. It could be a class or a struct.
The name of the object is C. Only for reference types does the CLR create a nameless object on the heap and a named value type that contains it's address. From the code snippet it is not possible to tell if the type "sample" is a reference type or a value type. It could be a class or a struct.
Vinay said:
1 decade ago
First the right part of sign is executed i.e new sample() which is nameless object & then it's reference is assigned to C.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers