OOPS interview questions and answers in C#.NET

1)What is the difference between Object based programming and Object oriented programming?

   -if a language supports only encapsulation then it is called as object based programming
    language
    ex:vb
  -if a language supports encapsulation,inheritance  and polymorphism then it is called as
   object oriented programming language.
  ex:c#,java,c++

2)What are the main concepts of oops?


     There are four main concepts in oops
      a)Encapsulation
      b)Inheritance
      c)Polymorphism
      d)Abstraction

3)What is encapsulation and its advantage?


    -Grouping of related things together is called as encapsulation.
    -due encapsulation we can achieve portability.

4)What is Data hiding?

    -Hiding unnecessary information from user is called as datahiding.
    -due to data hiding we can protect behaviour of component.
   -data hideing can be implemented by using access modifiers.

5)What is abstraction?


   -Hiding complete implementation details from user is called as abstraction.
  -Due to abstraction we can make user to feel easy and confortable while using component.

6)What is the difference between data hiding and abstraction?


   -DataHiding is hiding unnecessary information from user,so that we can protect behaviour
   of component.
  -Abstraction is hiding of complete implementation details,so that component usage becomes
   easy.

7)What is the difference between encapsulation and class?

    -Encapsulation is oops concept but class is feature of language by which we can implement
    encasulation.

8)How to implement encapsulation in C#?


   -By using class,struct,interface,enum.

9)What are the access specifiers ? (or) 
What are the access modifiers?

    There are six access modifiers
    a)private
    b)protected
   c)Public
   d)internal.
   e)protected internal
   d)private protected.

10)What  is the behavior  of protected internal?


     -protected internal is combination of two access modifiers.
     -with in same assembly it will be like a internal,outside assembly it will be like a
     protected.so that we can make us of it in any class of same assembly and only derived
     classes outside assembly.

10)What  is the behavior  of private protected ?

     - it is available from C#7.2
     -protected internal is combination of two access modifiers.
     -within in same assembly by the code in same class and can access it from its derived class

11)What is object?


     -it is instance of class.

12)What is min size of object if there is no member in class?


    -8bytes

13)What is default access modifier for class?

   -internal

14)What is default access modifier for members in class?

   -private

15)What is the base class for all classes in .net?


    -System.Object.

15)What is the difference between value types and reference types?

Value type store the values in stack.
Value type directly stored the values rater than address.
ex: int y =100;

Reference type store the values in heap.
Reference type store the address of the value ,actually value stored in other location.
ex: string name="Shiva";

16)What is the difference between class and structure?

     Class                                                    struct
  -it is reference type                            -it is value type
 -all access modifiers allowed              -protected not allowed.
-all types of methods allowed              -Virtual and abstract methods not allowed.
-destructor is allowed                          -destructor not allowed.
-all types of constructors allowed       -default constructor not allowed.
-Inheritance possible                          -inheritance not posssible
-it can implement interface                -it also can implement interface.

17)Is it possible to define method in enum type?

     -no

18)How to initialize object?


     -in two ways we can initialize object.
      a)by using object initializer.
      b)By using Constructor.

19)What are accessor and mutator methods?

      -a method which is designed to get value from variables of class is called as accessor method.
      -a method which is designed to modify values of variables of class is called as mutator method.

20)What is the difference between property and indexer?


 -property is member of class or struct which provides flexible mechanism to read and write from and to the variable of class or struct.
 -it can be static.
 -it can not be overloaded.
   
-Indexer is also member of class or struct which is also providing flexible mechanism to read and write from and to the variable of class or struct by using subscript and index.
-indexer can not be static.
-always name of indexer must be this,and it can be overloaded

21)Is it possible to define property as static?


     -yes

22)Is it possible to define indexer as static?


    -no

23)What is the use of base keyword?


  -with the help of base keyword we can access base class members from derived class.
  -allways base keyword  will refer to immediate base class members.
 -we can call base class constructor from derived class constructor.

24)What is Constructor?

     -it is special method in the class which is invoked automatically when the class has been instantiated.
     -it can be used to initialize instance variables of class to some meaningfull initial values
      once object has been created.

25)Why name of constructor and class name must be same?


       -to make the compiler to identify it easily.

26)Why return type is not allowed for constructor at programmer level?


      -constructor should not be used for any other purpose,it must be used for only initialization.

27)What are different types of constuctors available?


      -static constructor
     -non static constructor
       a)default constructor
       b)parametric constructor.

28)Explain static constructor?


      -A constructor can be defined as static member.
     -static constructor should not have access modifier
    -it must be parameter less.
   -it can not be overloaded.
   -it can be used to initialize static variables of class but not non static variables.
  -it is invoked one and only once when the class has been loaded into appDomain by class loader.

29)When the static constructor is invoked?


    -it is invoked one and only once when the class has been loaded into appDomain by class loader.

30)Is it possible to overload static constructor?


   -no

For Part-2  click here


Thanks for visiting this blog. How is the content?. Your comment is great gift to my work. Cheers.

No comments:

Post a Comment