Job Interview: .NET OOP questions
I tried to collect here most popular question about OOP from some sites around internet.
What is OOP?
Object Oriented Programming - is a programming paradigm that uses "objects" and their interactions to design applications and computer programs. Is one of the most popular methodologies in software development. It offers a powerful model for creating computer programs. It speeds the program development process, improves maintenance and enhances re usability of programs.
What is object?
An object is a combination of messages and data. Objects can receive and send messages and use messages to interact with each other. The messages contain information that is to be passed to the recipient object.
What is the syntax to inherit from a class in C#?
Place a colon and then the name of the base class.
Example: class MyNewClass : MyBaseClass
Does a class inherit the constructors of its superclass?
A class does not inherit constructors from any of its super classes.
Does exist Virtual Constructor?
Constructor cannot be virtual because at the time when the constructor is invoked the virtual table would not be available in the memory. Hence we cannot have a virtual constructor. But we have pattern for create Virtual constructor. It should be possible to create different type of objects depending on a given object. The Virtual Constructor pattern is also called Factory.
What is Virtual destructor?
A virtual destructor is one that is declared as virtual in the base class and is used to ensure that detractors are called in the proper order. It is to be remembered that detractors are called in the reverse order of inheritance. If a base class pointer points to a derived class object and we some time later use the delete operator to delete the object, then the derived class detractor is not called.
Can you prevent your class from being inherited by another class?
Yes. The keyword “sealed” will prevent the class from being inherited.
Can you allow a class to be inherited, but prevent the method from being over-ridden?
Yes. Just leave the class public and make the method sealed.
What’s an abstract class?
A class that cannot be instantiated. An abstract class is a class that must be inherited and have the methods overridden. An abstract class is essentially a blueprint for a class without any implementation.
When do you absolutely have to declare a class as abstract?
1. When the class itself is inherited from an abstract class, but not all base abstract methods have been overridden.
2. When at least one of the methods in the class is abstract.
What is an interface class?
Interfaces, like classes, define a set of properties, methods, and events. But unlike classes, interfaces do not provide implementation. They are implemented by classes, and defined as separate entities from classes.
Why can’t you specify the accessibility modifier for methods inside the interface?
They all must be public, and are therefore public by default.
Can you inherit multiple interfaces?
Yes. .NET does support inherit multiple interfaces.
Can you inherit multiple classes?
Not. .NET doesn't support inherit multiple classes.
What happens if you inherit multiple interfaces and they have conflicting method names?
It’s up to you to implement the method inside your own class, so implementation is left entirely up to you. This might cause a problem on a higher-level scale if similarly named methods from different interfaces expect different data, but as far as compiler cares you’re okay.
What’s the difference between an interface and abstract class?
In an interface class, all methods are abstract - there is no implementation. In an abstract class some methods can be concrete. In an interface class, no accessibility modifiers are allowed. An abstract class may have accessibility modifiers.
What is the difference between a Struct and a Class?
Structs are value-type variables and are thus saved on the stack, additional overhead but faster retrieval. Another difference is that structs cannot inherit.
Some another subjects for interview:
High transaction Websites
Sources:
www.interviewquestion.us
placementpapers.net
www.coders2020.com

0 comments:
Post a Comment