OOPs Interview Questions: Get your Basics Right To Get a Job!

oopsinterviewquestionsMost major programming languages in use today like Java, C++ and Visual Basic are all object-oriented. Hence a large chunk of programs written today employ Object Oriented Programming (OOP) in one form or another. Programmers specializing in OOP languages are in high demand. Are you one of them? Do you want to be one of them? Programming is fun and pays well at the same time. Yet most people are afraid of it, simple because they don’t know it, and they don’t know how to get started. Today there are many resources available online to help you learn, whether you are trying to master C++ , learn Java, or write your own iOS application.

Yes, it’s always hard to impress the interviewer, beat the competition and land the job! To help you crack the OOP interview, we have put together a list of basic OOPs questions that you’re likely to be asked. Remember, most interviewers want to make sure you have a good grasp on the basics, so that they know they can move you on to more complex stuff. It always helps to have a programming portfolio say a game on Android or an iPhone App to your credit, to back up your claims.

1. What is Object-Oriented Programming?

This is probably the first question you’ll be asked. Object-Oriented Programming, as the name suggests, deals with Objects. Objects are used to emulate real world objects, and then they are assigned to a class. An object will have attributes and behaviour similar to the other objects in the class. OOP is focused on manipulating these objects, through a collection of classes and methods, to get the desired result. OOP can be used for complex tasks and for creating large amounts of structured and interlinked code.

2. What is an Object in OOP?

An Object in OOP is a basic member of a class. It often resembles real world objects (pen, car, etc.) It is the basic instance of a class, and it has its own attributes, identity and state. The operator “new” is used to create an object in OOP languages.

3. What is a Class in OOP?

A class typically includes several member objects. A class will describe the behaviour and attributes of its member. It will also describe the methods that can be used to manipulate its objects. This represents  a class as a template, or a basic representation, of its member objects.  A class is typically a universal concept. For example, if you have objects that are mammals, amphibians and invertebrates, the class could be Animals.

4. What are the Attributes of OOP/ what are the Features of OOP?

Basic concepts of OOPs revolve around the following

  • Class and Structure: Classes are used as a reference, for grouping both data and methods. Classes have to include constructors and destructors, and they support the concept of inheritance. Classes can also contain null variables. Structures are just used to group data. They don’t support inheritance, they cannot include variables with null value and they can be initialized automatically (they don’t require constructors/destructors).
  • Overriding and Overloading: Methods are used to manipulate classes. Overriding refers to creating two, or more, methods that have the same name and the same signature, but belong to different classes. This concept is implemented between a parent and a child class (or classes).   Overloading allows the programmer to use a method of the same name, but with different signature, within a class. Remember, you cannot declare an overridden method as static, if the original method is dynamic.

There are four basic attributes of OOP:

  • Polymorphism: This allows the programmer to re-use a function, object or variable in several forms. Typically, a program will have classes and sub-classes. A function used in the main class can be re-used in the base classes.

  • Encapsulation: Information and code can be bound as an object, which prevents unwarranted access.

  • Data Abstraction: Related to encapsulation. Only relevant data is displayed to the user of the program.

  • Inheritance: Large tracts of code can be reused in OOPs. Code defined in a parent class (main class) can be re-used in the sub-classes through the Inheritance feature of OOP. Sub-classes “inherit” the properties of their parent classes. To inherit a class, you can use the following code snippet:

Class OldClass
Class NewClass : Class OldClass{}

5. What are the types of Inheritance in OOP?

There are four types of inheritance in OOP:

  • Single inheritance: Single inheritance is the simplest form of inheritance. A single class derived from single parent class displays single inheritance.

  • Multilevel inheritance: Multilevel inheritance shows a class derived from a class that has one or more parent classes.

  • Multiple inheritance: A class that is inherited from more than one parent class, or from the subclasses of those parent classes.

  • Hierarchical inheritance: Hierarchical inheritance is shown by a multiple derived classes from a single base class.

6. Can you Prevent Inheritance?

Yes, you can prevent inheritance through the use of sealed modifier. Sealed can prevent the inheritance of a class or a method. For example:

Class Books {}
sealed class Fiction : Books {}

7. Have you heard of bindings? What are Static and Dynamic Binding?

Binding is associating a name with a class, during or after compilation of a program. Binding done during the compilation time is known as static binding. Binding done during the execution of the program, after the code has been writing, is known as dynamic binding.

Remember, this is just the tip of the iceberg. To improve your chance of clearing the programming round, make sure you’ve practised coding as well! It’s very likely you will have to write a complex program or two in addition to answering questions!  Don’t forget that the interviewer will also be evaluating you based on your presentation, your communication skills, your aptitude, your approach to problem solving and a host of other parameters. Make sure you keep your cool and come across as calm, confident and capable.  What are you waiting for  now? Go ace that interview!