20 C# Programming Questions on Object Oriented Concepts

Check out 20 C# OOPS interview questions and answers for experienced. Answer each question and identify any gaps before appearing in any interview.

Before you begin to read the interview questions, let’s quickly wrap the concepts of classes and objects in C#.

The primary building blocks of object-oriented programming are the class & the object.

A class outlines the available characteristics and behavior of a set of identical objects which a programmer creates in his code. Whereas an object is the abstract form of a class that turns concrete at run-time and take on the class’s behavior.

Test Your C# OOPS Skills.

Classes, Accessibility and Modifiers in C#.

A class declaration encompasses a header and body.

The class header carries attributes, modifiers, and the class keyword.

Whereas its body encapsulates the members of the class, that could be data and functions both. Look at the syntax of a class declaration in C#.

Attributes extend the context to a class like adjectives, e.g. the Serializable attribute. Accessibility represents the visibility of the class. By default, a class has internal accessibility. Whereas its members are private by default. The following is the list of accessibility keywords in C#.

  • Public – Visible in the current and referencing assembly.
  • Private – Visible inside the current class.
  • Protected – Visible inside the current as well as in the derived class.
  • Internal – Visible inside the containing assembly.
  • Internal protected – Visible inside the containing assembly, also in the descendent of the current class.

Next are the modifiers which refine the declaration of a class. Here is the list of all supported modifiers in C#.

  • Sealed – The class stops inheriting by any derived class.
  • Static – The class contains only static members.
  • Unsafe – The class that stores unsafe types likes pointers.
  • Abstract – No instance of the class if the Class is abstract.

In the below section, find out 20 C# OOPS interview questions for experienced.

20 C# OOPS interview questions and answers.

C# OOPS Interview Questions

C# OOPS Interview Questions

Q-1. What will be the output of the following code snippet?

a) 40, 25000, 50000
b) 40, 25000, 25000
c) 40, 50000, 50000
d) Error

Check correct option.
Answer. a)

 

Q-2. Which of the following keyword, enables to modify the data and behavior of a base class by replacing its member with a new derived member?

a) overloads
b) overrides
c) new
d) base

Check correct option.
Answer. c)

 

Q-3. Which of the following is the correct way to overload “+” operator?

a) public sample operator + ( sample a, sample b)
b) public abstract operator + (sample a, sample b)
c) public static sample operator + (sample a, sample b)
d) All of above

Check correct option.
Answer. d)

 

Q-4. What will be the correct order of execution of function func1(), func2() & func3() in the given code snippet?

a) func1() of derived class get executed
    func2() of derived class get executed
    func3() of base class get executed
b) func1() of base class get executed
    func2() of derived class get executed
    func3() of derived class get executed
c) func1() of derived class get executed
    func2() of base class get executed
    func3() of base class get executed
d) func1() of base class get executed
    func2() of derived class get executed
    func3() of base class get executed

Check correct option.
Answer. d)

 

Programmers Should Also Follow the Below Post.

 

Q-5. Which of the following statements are correct for C# language?

a) Every derived class does not define its own version of the virtual method.
b) By default, the access mode for all methods in C# is virtual.

c) If a derived class, does not define its own version of the virtual method, then the one present in the base class gets used.
d) All of the above.

Check correct option.
Answer. b)

 

Q-6. Which of the following code needs to be added for the overloaded operator “-” in C#?

a) 

b)

c)

d) None of the above

Check correct option.
Answer. c)

 

Q-7. Which of the following is the correct name for selecting an appropriate method from a number of overloaded methods, by matching the arguments in terms of their number, type, order, and binding at compile time?

a) Late binding
b) Static binding.
c) Static Linking.
d) Compile time polymorphism.

Check correct option.
Answer. b), c) and d)

 

Q-8. Which of the following statements are correct for run-time polymorphism?

a) The overridden base method should be virtual,abstract or override.
b) An abstract method is implicitly a virtual method.
c) An abstract inherited property cannot be overridden in a derived class.
d) Both override method and virtual method must have same access level modifier.

Check correct option.
Answer. a), b), and d)

 

Q-9. What will be the output of the following code snippet?

a) constructor 1 called
    constructor 2 called
b) constructor 2 called
    constructor 1 called

c) constructor 2 called
    constructor 2 called
d) error

Check correct option.
Answer. b)

 

Q-10. Which of the following keywords is used to refer base class constructor to subclass constructor?

a) this
b) static
c) base
d) extend

Check correct option.
Answer. c)

 

Q-11. What will be the output of the following code snippet?

a) TechBeamers
b) 12 Tech
c) Beamers 12
d) Compile time error

Check correct option.
Answer. a)

 

Q-12. What will be the output of the following code snippet?

a) 4, 26, 144
b) 26, 4, 144
c) 144, 26, 4
d) 0, 0, 0

Check correct option.
Answer. c)

 

Q-13. What will be the output of the following code snippet?

a) 10, 10
b) 0, 10
c) 8, 10
d) 8, 8

Check correct option.
Answer. c)

 

Q-14. What will be the output of the following code snippet?

a) 25
    1000
b) -25
    -1000
c) -25
     1000
d) 25
    -1000

Check correct option.
Answer. a)

 

Don’t Miss to Check out this Awesome Post.

 

Q-15. Which of the following options represents the type of class which does not have its own objects but acts as a base class for its subclass?

a) Static class
b) Sealed class
c) Abstract class
d) Derived class

Check correct option.
Answer. c)

 

Q-16. What will be the output of the following code snippet?

a) 1, 5
b) 0, 5
c) 1, 0
d) 1, 3

Check correct option.
Answer. d)

 

Q-17. What will be the output of the following code snippet?

a) 2  10
Sum is: 12
b) 0  10
Sum is: 10
c) 2  0
Sum is: 2
d) 0  0
Sum is: 0

Check correct option.
Answer. c)

 

Q-18. Which of the following represents a class that inherits an abstract class but it does not define all of its functions?

a) Abstract
b) A simple class
c) Static class
d) derived class

Check correct option.
Answer. a)

 

Q-19. What will be the output of the following code snippet?

a) 0, 8
b) 1, 8
c) 1, 7
d) 7, 1

Check correct option.
Answer. d)

 

Q-20. What will be the output of the following code snippet?

a) 8, 1
b) 8
c) 1
d) 1, 8

Check correct option.
Answer. c)

Summary – 20 C# OOPS interview questions for experienced.

In this post, we covered twenty C# OOPS interview questions and targetted a broad range of C# programming concepts.

We hope you have enjoyed going through the list of questions.

Thanks for reading!

TechBeamers.

Leave a Reply


*