Object-oriented programming (OOPs) Interview Preparation Guide
Strengthen your OOP interview skills with our collection of 37 important questions. These questions are specifically selected to challenge and enhance your knowledge in OOP. Perfect for all proficiency levels, they are key to your interview success. Dont miss out on our free PDF download, containing all 37 questions to help you succeed in your OOP interview. Its an invaluable tool for reinforcing your knowledge and building confidence.37 OOP Questions and Answers:
1 :: What is Abstract method?
Abstract method doesn't provide the implementation & forces the derived class to override the method.
2 :: What is Virtual method?
Virtual Method has implementation & provide the derived class with the option to override it.
3 :: What is Polymorphisms?
Polymorphism means one interface and many forms. Polymorphism is a characteristics of being able to assign a different meaning or usage to something in different contexts specifically to allow an entity such as a variable, a function or an object to have more than one form.
There are two types of Polymorphism.
Compile time: function or operator overloading
Runtime: Inheritence & virtual functions
There are two types of Polymorphism.
Compile time: function or operator overloading
Runtime: Inheritence & virtual functions
4 :: What is Abstract Class?
Abstract class is a class that can not be instantiated, it exists extensively for inheritance and it must be inherited. There are scenarios in which it is useful to define classes that is not intended to instantiate; because such classes normally are used as base-classes in inheritance hierarchies, we call such classes abstract classes.
Abstract classes cannot be used to instantiate objects; because abstract classes are incomplete, it may contain only definition of the properties or methods and derived classes that inherit this implements it's properties or methods.
Static, Value Types & interface doesn't support abstract modifiers. Static members cannot be abstract. Classes with abstract member must also be abstract.
Abstract classes cannot be used to instantiate objects; because abstract classes are incomplete, it may contain only definition of the properties or methods and derived classes that inherit this implements it's properties or methods.
Static, Value Types & interface doesn't support abstract modifiers. Static members cannot be abstract. Classes with abstract member must also be abstract.
5 :: When to use Interface over abstract class?
Abstract Classes: Classes which cannot be instantiated. This means one cannot make a object of this class or in other way cannot create object by saying ClassAbs abs = new ClassAbs(); where ClassAbs is abstract class.
Abstract classes contains have one or more abstarct methods, ie method body only no implementation.
Interfaces: These are same as abstract classes only difference is we can only define method definition and no implementation.
When to use wot depends on various reasons. One being design choice.
One reason for using abstarct classes is we can code common
functionality and force our developer to use it. I can have a complete
class but I can still mark the class as abstract.
Developing by interface helps in object based communication.
Abstract classes contains have one or more abstarct methods, ie method body only no implementation.
Interfaces: These are same as abstract classes only difference is we can only define method definition and no implementation.
When to use wot depends on various reasons. One being design choice.
One reason for using abstarct classes is we can code common
functionality and force our developer to use it. I can have a complete
class but I can still mark the class as abstract.
Developing by interface helps in object based communication.
6 :: What is Sealed modifiers?
Sealed types cannot be inherited & are concrete.
Sealed modifiers can also be applied to instance methods, properties, events & indexes. It can't be applied to static members.
Sealed members are allowed in sealed and non-sealed classes.
Sealed modifiers can also be applied to instance methods, properties, events & indexes. It can't be applied to static members.
Sealed members are allowed in sealed and non-sealed classes.
7 :: What is Inheritance?
It provides a convenient way to reuse existing fully tested code in different context thereby saving lot of coding.
Inheritance of classes in C# is always implementation Inheritance.
Inheritance of classes in C# is always implementation Inheritance.
8 :: What is New modifiers?
The new modifiers hides a member of the base class. C# supports only hide by signature.
9 :: What is Virtual keyword?
This keyword indicates that a member can be overridden in a child class. It can be applied to methods, properties, indexes and events.
10 :: What is an Interface?
An interface is a contract & defines the requisite behavior of generalization of types.
An interface mandates a set of behavior, but not the implementation. Interface must be inherited. We can't create an instance of an interface.
An interface is an array of related function that must be implemented in derived type. Members of an interface are implicitly public & abstract.
An interface can inherit from another interface.
An interface mandates a set of behavior, but not the implementation. Interface must be inherited. We can't create an instance of an interface.
An interface is an array of related function that must be implemented in derived type. Members of an interface are implicitly public & abstract.
An interface can inherit from another interface.