Select chapter



Basics (2.papers)
Data Types (2.papers)
enums (2.papers)
OOPS (4.papers)
Arrays (1.papers)
Structs (2.papers)
Properties (2.papers)
Strings (2.papers)
Interfaces (1.papers)
Constructors (2.papers)
Ref-Out-Keywords (1.papers)
Collections (2.papers)
Generics (1.papers)
Hide

Sponsored Links


  

c# properties interview questions and answers

1
What is a property in C# ?
  1. A property in C# used for modifying or retrieving data present private variables .
  2. A property in C# is a method which is having getter and setter for reading and modifying data present in private variables .
  3. Properties in C# are special methods called as accessors ( having get and set ).
  4. All the above definitions are correct .
Show Answer
Share Facebook gmail Twitter
2
What are the different types of properties available in C#?
  1. Read only properties.
  2. Read only and Write only properties.
  3. Read only, Write only and Read Write properties.
  4. Read only, Write only, Read write and Constant properties.
Show Answer
Share Facebook gmail Twitter
3
A Student class has a public property called Sid and std is reference to Student object . Now we want the statement Console.WriteLine(std.Sid) to be failed during compilation. Which of the following options will ensure this functionality?
  1. Declare Sid property with both get and set accessors.
  2. Declare sid property with only set accessor.
  3. Declare sid property with only get accessor.
  4. None of the above
Show Answer
Share Facebook gmail Twitter
4
Which of the following is the correct way to implement a read only property height in a Student class?
  1. class Student
    {
        public int Height
        {
            get
            {
                return height;
            } 
        } 
    }
  2. class Student
    {
        int height;
        public int Height
        {
            get
            {
                return height;
            } 
        } 
    }
  3. class Student
    {
        int hei;
        public int Height
        {
            Readonly get
            {
                return hei;
            } 
        } 
    }
  4. class Student
    {
        int height;
        public int Height
        {
            get
            {
                return height;
            } 
            set
            {
                height = value;
            }
    }
Show Answer
Share Facebook gmail Twitter
5
Which of the following statement are true about properties used in C#.NET?
  1. Properties cannot be overloaded.
  2. We can override a property.
  3. Properties of a class are actually methods that work like data members.
  4. All the above.
Show Answer
Share Facebook gmail Twitter
6
What is an auto implemented property in C# ?
  1. An auto implemented property is a property which is having get and set without any code in getter and setter.
  2. An auto implemented property is a property which is created automatically without writing any code for private variables.
Show Answer
Share Facebook gmail Twitter
7
Which of the following statements are true about properties used in C#.NET?
  1. Properties cannot be overloaded, because properties do not have signature.
  2. Every property must have a set accessor and a get accessor.
  3. A property has to be either read only or a write only.
  4. Properties can not be static
Show Answer
Share Facebook gmail Twitter
8
Which of the following statements is false about properties used in C#.NET?
  1. Properties can not be virtual.
  2. Properties can't be overloaded.
  3. Properties of a class are actually methods that work like data members.
  4. Every property must have either a set accessor or a get accessor.
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
13
What is the difference between virtual and abstract properties?
  1. Both are same.
  2. Both virtual and abstract properties should be having the implementation in a class in which they are  declared.
  3. Virtual property have implementation and Abstract property do not have implementation within declared class.
  4. We can override abstract properties and is not possible for virtual properties.
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
15
What is the default access specifier for get and set accessors in properties?
  1. public
  2. protected
  3. private
  4. Same access specifier as the property in which they are present.
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
19
What is the problem in the below property ?
private int _age;
 public int Age
  {
          private  get{return _age;}
          protected  set{_age = value;}
   }
  1. Not allowed to specify access modifiers to accessors
  2. Should not specify access modifier for a property
  3. Access modifier of either setter or getter should be same as access modifier of property
  4. Not allowed to give private access specifier for either setter or getter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Read more papers :