OOP Interview Questions and Answers
There are still people, for instance, that call Artificial Intelligence to any program that is written in Prolog or Lisp. In the same way, there are those who maintain that any program written in Smalltalk, C++ or Objective C is OOP. A given application is a hierarchical set of programs (modules) each of which is capable of invoking other programs in the hierarchy. We can herewith list of latest and updated OOP Interview Questions and their answers for fresher’s as well as experienced users. These JavaScript interview question covers latest version of OOP.
Best OOP Interview Questions and Answers
The data may be global (accessible from every program in the hierarchy) or local (accessible by the program where they belong and, sometimes, by those at a lower level in the hierarchy). In Object-Oriented Programming (OOP in short), things are different. Here you can find top best OOP Interview Questions and Answers for beginners and professionals,
What is Abstract method?
Abstract method doesn’t provide the implementation & forces the derived class to override the method.
What is Virtual method?
Virtual Method has implementation & provide the derived class with the option to override it.
What is Polymorphisms?
Polymorphism means one interface and many forms. Polymorphism is 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: Inheritance & virtual functions
What is Abstract Class?
Abstract class is a class that cannot 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.
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.
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.
What is New modifiers?
The new modifiers hides a member of the base class. C# (C Programming) supports only hide by signature.
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.
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.
What is Static Method?
It is possible to declare a method as Static provided that they don’t attempt to access any instance data or other instance methods.
What is Class?
A Class is the generic definition of what an object is a template. The keyword class in C# indicates that we are going to define a new class (type of object).
What is Object?
Object is anything that is identifiable as a single material item.
Can Struct be inherited?
No, Struct can’t be inherited as this is implicitly sealed.
What is Method Overriding? How to override a function in C#?
Use the override modifier to modify a method, a property, an indexer, or an event. An override method provides a new implementation of a member inherited from a base class. The method overridden by an override declaration is known as the overridden base method. The overridden base method must have the same signature as the override method.
You cannot override a non-virtual or static method. The overridden base method must be virtual, abstract, or override.
What is Method overloading?
Method overloading occurs when a class contains two methods with the same name, but different signatures.
What is Overriding?
Method overriding is a feature that allows to invoke functions (that have the same signatures) and that belong to different classes in the same hierarchy of inheritance using the base class reference. In C# it is done using keywords virtual and overrides.
Default Access modifiers in C#?
An enum has default modifier as public.A class has default modifiers as private. It can declare members (methods etc) with following access modifiers: public
What is Protected Internal access modifier in CO
Protected Internal is a access modifiers for the members (methods or functions) ie. you can’t declare a class as protected internal explicitly. The members access is limited to the current assembly or types derived from the containing class.
Protected Internal means the method is accessible by anything that can access the protected method UNION with anything that can access the internal method.
What is Protected access modifier in C#?
The protected keyword is a member access modifier. It can only be used in a declaring a function or method not in the class ie. a class can’t be declared as protected class.
A protected member is accessible from within the class in which it is declared, and from within any class derived from the class that declare this member. In other words access is limited to within the class definition and any class that inherits from the class. A protected member of a base class is accessible in a derived class only if the access takes place through the derived class type.
What is Internal access modifier in C#?
The internal keyword is an access modifier for types and type members ie. we can declare a class as internal or its member as internal. Internal members are accessible only within files in the same assembly (All). In other words, access is limited exclusively to classes defined within the current project assembly.
What is Private access modifier in C#?
The private keyword is a member access modifier ie. we can’t explicitly declare a class as Private, however if do not specify any access modifier to the class, its scope will be assumed as Private. Private access is the least permissive access level of all access modifiers.
Private members are accessible only within the body of the class or the struct in which they are declared. This is the default access modifier for the class declaration.
What is Public access modifier in C#?
The public keyword is an access modifier for types and type members ie. we can declare a class or its member (functions or methods) as Public. There are no restrictions on accessing public members.
What is pure virtual function in OOP?
When you define only function prototype in a base class without and do the complete implementation in derived class. This base class is called abstract class and client won’t able to instantiate an object using this base class.
What are Constructors?
Constructors are used for initializing the members of a class whenever an object is created with the default values for initialization.
If no constructor defined then the CLR will provide an implicit constructor which is called as Default Constructor.
A class can have any number of constructors provided they vary with the number of arguments that are passed, which is they should have different signatures.
What is Polymorphism?
In OPP’S, polymorphism(Greek meaning “having multiple forms”) is the ablity of being able to assign a different meaning or usage to something in different contexts – specifically, to allow an entity such as a function, or an object to have more than one forms.
In C# : Parent classes may define and implement “virtual” methods (Which is done using the “virtual” keyword), and derived classes can override them (using the “override” keyword), which means they provide their own definition and implementation. At run-time, when user’s code calls the method, the CLR looks up the run-time type of the object, and invokes that override of the virtual method. Thus in your source code when a method of the base class is called it executes the overriden method.
Can we declare private class in a Namespace?
No. If you try to create a private class in a Namespace, Compiler will throw a compile time error “Namespace elements cannot be explicitly declared as private, protected, or protected internal”.
Reason: The message says it all. Classes can only be declared as private, protected or protected internal when declared as nested classes, other than that, it doesn’t make sense to declare a class with a visibility that makes it unusable, even in the same module. Top level classes cannot be private, they are “internal” by default, and you can just make them public to make them visible from outside your DLL.
Thus, the compilation of these OOP questions includes some of the major points that can be asked during an interview. The OOP interviewers generally check the base knowledge of a candidate, which can be gained by practicing these OOP questions prior interview.
So if you have finally found your dream job in OOP but are wondering how to crack the OOPL Interview and what could be the probable OOP Interview Questions. Every interview is different and the scope of a job is different too. Hope above assist you to get a dream Job. Keep Learn.