c# structs interview questions and answers paper 219 - skillgunNote: Paper virtual numbers may be different from actual paper numbers . In the page numbers section website displaying virtual numbers .
Why inheritance is not supported on value types ?
Value types are created in Heap memory , Inheritance is not allowed on the members which are created in Heap memory .
Since value types are created in stack memory and stack memory is limited memory. Hence inheritance is not allowed .
Struct is value type, value types are usually created in stack memory. stack memory is limited memory and not expandable hence inheritance is not allowed .
Why struct members can not be declared as virtual?
By default structs are sealed.
Inheritence is not allowed on structs.
Interface implementaion is not allowed on structs.
Options 1 & 2 are correct.
Since structures do not support inheritance, structure members cannot be specified as virtual.
Why struct members can not be declared as abstract?
Since a struct can not act as a base type hence abstract keyword is not allowed .
Struct is sealed .
Since structures do not support inheritance, structure members cannot be specified as abstract.
Why struct members can not be declared as protected?
Cannot specify an access modifier for structs
They are public by default
They are private by default
Inheritence is not supported on structs.
Since structures do not support inheritance, structure members cannot be specified as protected.
Is it possible to implement multiple interfaces in a struct ?
Yes, but explicit implementation of Interface is not supported.
Yes, but implicit implementation of Interface is not supported.
Structures cannot inherit other structures or classes or be used as a base for other structures
or classes. (All structures do, however, implicitly inherit System.ValueType, which inherits
object.) However, a structure can implement one or more interfaces.
Is it possible to declare a constant in a struct ?
Inside a struct we can declare constants as well as readonly variables .
Is it possible to declare and initialise read-only variables in a struct ?
No, only declaration is allowed
No, Declaration as well as assignment are not allowed
None of the above
Declaration of read-only variables are allowed but not initialization.
Is it Possible to Write nested Structs?
Yes, we can write upto 32 levels
Is it possible to create parameterless constructor in structs?
You cannot define a default (parameterless)constructor for a structure. JIT compiler will automatically create default constructor, hence we are not allowed create default constructor in structs. The default constructor initializes the fields of a structure to their default value
Can Struct Contain Properties?
Like classes, structure members include methods, fields, indexers, properties, operator methods, and events. Structures can also define constructors(Only parameterized)
Which of the below given statements are correct about the below given program ?
public class Test
public static void main(string args)
int i = new int();
During compilation time value type int will be converted into Int32 struct.
We cannot use new keyword on value types.
All primitive types are finally converted into structs except string.
Which of the below statements are correct about structs?
Structs are reference types.
Garbage Collector cannot act on Structs.
Structures are equivalent to Light weight classes.
Most of the primitive types in .Net are structs
Garbage Collector can act only on the heap memory
What is the equivalent data types for int in msil language ?
Back To Top