2016-12-14

In our previous post, we’ve covered basic C# object-oriented concepts along with a set of 20 questions. Now it’s time to share the second edition of C# object-oriented interview questions.

Before you begin to read the questions, let us tell you two important C# object-oriented concepts i.e. Multiple Class Declaration and Partial Classes.

Multiple Class Declaration – When you require multiple classes and need to use them interchangeably, then declare them inside a single namespace. In this way, you won’t have to add it separately to the project. Instead, you place it along with the main class of your program.

Partial classes – There could be a situation when multiple developers are working on a single class. Then, a question arises – how each of them can work with the class without interfering other’s work. To solve this, C# provides the partial keyword that allows a class to span over multiple files.

During compilation, the C# compiler bundles all the partial types into a single assembly. However, a developer has to make sure the following rules while using the partial keyword.

All partial types are using the same accessibility.

Each of the partial types should use the “partial” keyword as a prefix.

If the partial type is sealed, then it must apply to the entire class.

Now you can check out the below C# interview questions.

C# Object-Oriented Interview Questions Set-2.



C# Object-Oriented Interview.

Q-1. Which of the following options define the correct way of implementing an interface data by the class employee?

a) class employee : data {}

b) class employee implements data {}

c) class employee imports data {}

d) None of the mentioned

Show correct answer.

Option a)

Q-2. Which of the following correctly defines the implementation of the interface mentioned below?

a)

b)

c)

d) None of the mentioned

Show correct answer.

Option c)

Q-3. Which of the following Access specifiers can be used for an interface?

a) Public

b) Protected

c) Private

d) All of the above

Show correct answer.

Option a)

Q-4. Which of the following statements is correct for the below code snippet?

a) class B is an abstract class.

b) A method table would not be created for class B.

c) The definition of func1() in class B should be void A.func1().

d) All of the above.

Show correct answer.

Option c)

Q-5. Which of the following statements is correct for the below code snippet?

a) interface A to contain function definition.

b) properties cannot be declared inside an interface.

c) code compiles successfully.

d) All of the above.

Show correct answer.

Option c)

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

a) 0 0

b) 4 1

c) 2 2

d) 1 4

Show correct answer.

Option b)

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

a) inside function definition for A1

inside function definition for A2

b) inside function definition for A1

c) inside function definition for A2

d) inside function definition for A2

inside function definition for A1

Show correct answer.

Option a)

Q-8. Which of the following code snippet defines the correct way of representing an interface derived from two interfaces both having a method with the same name and signature?

a)

b)

c)

d) None of the above

Show correct answer.

Option c)

Q-9. Which of the following keywords can be used to access a member of the base class from derived class?

a) upper

b) base

c) this

d) None of the above

Show correct answer.

Option b)

Q-10. Which of the following statements are correct about the given code snippet?

a) ‘num’ variable should be declared as public if it is needed to be available in the inheritance chain.

b) ‘num’ should be declared as protected if it is to become available in the inheritance chain.

c) The constructor of the baseSample class does not get inherited in the derivedSample class.

d) During constructing an object referred to by z, firstly, the constructor of the baseSample class will be called followed by the constructor of the derivedSample class.

Show correct answer.

Option b), c) and d)

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

a) 10, 20, 30

inside base method

b) 10, 20, 0

c) inside base method

d) compile time error

Show correct answer.

Option d)
baseSample.i' and baseSample.j’ is inaccessible due to its protection level.

Q-12. What will be the size of the object created in the given code snippet?

a) 20 bytes

b) 12 bytes

c) 16 bytes

d) 24 bytes

Show correct answer.

Option d)

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

a) Code executes successfully prints nothing

b) This is base class constructor

c) Compile time error

d) None of the above

Show correct answer.

Option c)

Inconsistent accessibility: base class baseSample' is less accessible than class derivedSample’

Q-14. Which of the following statement should be included in the current set of code to get the output as 10 20?

a) Console.WriteLine(a + ” ” + base.a);

b) Console.writeline( a + ” ” + this.a);

c) Console.Writeline( mybase.a + ” ” + a);

d) console.writeline(base.a + ” “+ a);

Show correct answer.

Option a)

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

a) Compile time error

b) a

b

c) b

a

d) 20

20

Show correct answer.

Option b)

Q-16. Which of the following statement should be included in the given set of code to get the output as “Welcome to TechBeamers”?

a) base.print();

b) baseSample.print();

c) print();

d) baseSample::print();

Show correct answer.

Option a)

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

a) 2 1

b) 1 3

c) 3 1

d) 1 2

Show correct answer.

Option d)

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

a) 1 2

b) 1 3

c) 3 2

d) 3 3

Show correct answer.

Option c)

Q-19. Which of the following statements are correct for the base and derived classes?

a) If a base class consists of a member function fun() and a derived class do not have any function with this name. An object of derived class can access the base class fun() directly.

b) Class D can be derived from class C, which in turn gets derived from class B that is derived from class A.

c) If a base and a derived class, both include a member function with the same name. The member function of the derived class can be called by an object of the derived class.

d) The size of a derived class object is equal to the sum of sizes of data members in the base and derived class.

Show correct answer.

Option a), b), c), and d)

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

a)    Base class

b)    Derived1 class

c)    Derived2 class

d)    Base class Derived1 class

e)    Base class Derived1 class Derived2 class

Show correct answer.

Option a)

Summary – C# Object-Oriented Interview Questions Set -2.

We think these questions are very helpful for the people who are trying to get the job on C#/.NET. And we hope you’ll be able to get the most out of them.

However, if you’ll look up further on our blog, then you’ll see hundreds of other C# interview questions. Go through as many of them as you could and secure your seat in a top IT MNC.

Keep Learning,

TechBeamers.

The post C# Object-Oriented Interview Questions Set-2 appeared first on Python, Java, TestNG, Selenium Webdriver Tutorials.

Show more