If you are working or planning to work in any tech field, then you will probably need to know a little about programming languages. One of the most popular types of programming languages is OOP. Much of the world runs on this paradigm, and if you’ve just started into your tech career you may be expected to know the answers to some questions about it. To start, let’s figure out what OOP languages are, then we will consider some common questions asked by interviewers.
What is OOP?
OOP stands for Object-Oriented Programming, and it’s a type of programming paradigm. Languages that are object-oriented focus on objects rather than logic alone. Objects can hold both data and code, and in many OOP languages, almost everything is an object.
These objects can interact with each other, and with themselves. This is opposed to the other main branch of programming—functional programming—where the focus is on the flow of information and has immutable variables.
That said, here are the important questions you will need to remember in an interview for object-oriented programming languages.
Object-Oriented Programming Interview Questions
Q: Name some object-oriented languages.
A: Here are some common object-oriented languages:
Q: What are the pillars of OOP theory?
A: The four fundamental concepts are:
Q: What is abstraction?
A: With data abstraction, one can pull a small amount of relevant data from a larger amount of data. This allows you to see and use only the important information and leave some of the implementation details hidden out of the way.
Q: What is encapsulation?
A: Encapsulation refers to the idea that you can bundle data with code, and it’s a central tenet of object-oriented languages. It also allows for data hiding so that only the object with secure information can access that secure information.
Q: What is inheritance?
A: Inheritance is just what it sounds like. It allows for objects and classes to copy data and functions from other parent classes, and can serve as a template for objects and classes.
Q: What is polymorphism?
A: Polymorphism is the idea that one thing can appear in many forms. For object-oriented languages, this means that once designed, an instance of code can be used more than once in more than one situation.
Q: What is an object?
A: Objects are sets of both data and code, and function much like real-world objects. They can have both properties (like color, size, or weight) and a function (like stapling, heating, or typing).
Q: What is a class?
A: A class is an object that serves as a blueprint for more objects. It gives the basic definition and fundamental components for the objects created with it and is one of the core parts that allow inheritance. For example ‘soda’ or ‘computer’ could be classes, while ‘Fanta’ and ‘Thinkpad’ could be objects under those classes.
Q: What is a superclass?
A: A superclass—also called a base class—is a class that is a parent for more classes rather than objects. It usually contains the most basic code and data that will be used by every class and object under it. Using the above example, ‘beverage’ and ‘machine’ could be superclasses for ‘soda’ and ‘computer.’
Q: What is a subclass?
A: A subclass is a class that falls under a superclass. It inherits from the superclass and is considered to have an “is-a” relationship with the superclass.
Q: What are access modifiers?
A: Access modifiers affect the scope of a method or variable, and change what is allowed to see and modify these methods and variables. They include:
- Protected Friend
Q: What is a sealed modifier?
A: Sealed modifiers are access modifiers that cannot be inherited. Sealed modifiers can also be applied to properties, events, and methods.
Q: What is a constructor?
A: A constructor is a method used to create objects or classes, and initialize their state as required. It’s called at the time of the object’s creation.
Q: What is a copy constructor?
A: A copy constructor is a special method that creates an object that is a copy of an object.
Q: What is a parametric constructor?
A: This is a constructor that passes on certain defined parameters to the new object or class.
Q: What is a destructor?
A: A destructor is a method called when an object is destroyed.
Q: What is an inline function?
A: An inline function lets the compiler insert the entirety of a function wherever it is used in the uncompiled code.
Q: What is a friend function?
A: A friend function is a function that is permitted to access public, private, and protected information contained in the class it is ‘friends’ with. This function must be defined inside the aforementioned class.
Q: What is operator overloading?
A: Operator overloading adds additional functionality for operators specific to certain classes so that the same operator can be used in different cases and perform different functions.
Q: What is function overloading?
A: Function overloading is much like operator overloading. It means creating a function that can be used in different situations and can have different parameters depending on where it’s used.
Q: List the operators that cannot be overloaded
A: The following cannot be overloaded:
- Scope Resolution (represented by ‘::’)
- Member Selection (represented by ‘.’)
- Member selection through a pointer to function (represented by ‘.*’)
Q: What is an abstract class?
A: An abstract class is a special type of class that contains one or more abstract methods and cannot create instances. Abstract classes cannot create objects, but they do allow for inheritance.
Q: What is an interface?
A: An interface is a collection of one or more abstract methods.
Q: What is the difference between a structure and a class?
A: A structure is used for grouping data and is public by default. Classes group both data and methods and are private. Classes are also used for inheritance and encapsulation, while structures are not.
Q: What is a ternary operator?
A: A ternary operator is an operator that takes three arguments rather than two.
Q: What is the finalize method?
A: The finalize method is used for cleanup operations at the end of your code and it saves memory by cleaning up unused resources. It’s protected and only accessible via this class or a subclass.
Q: What is exception handling?
A: Exceptions are events that occur when the program runs. These events can be errors, runtime exceptions, etc. Exception handling handles these exceptions with try, throw, and catch keywords.
Q: What is early binding?
A: Early binding is when variables are assigned values before the program is compiled and run: directly in the code.
Q: What is late binding?
A: Late binding is when variables are assigned values after the program has been compiled: on or during runtime.
Q: What is static binding?
A: Static binding is when the type of a variable is determined by compile time. These are usually variables that are explicitly set in your code
Q: What is dynamic binding?
A: This is when the type of a variable is determined at runtime. This is usually done implicitly.
Q: What is a pointer?
A: A pointer is a memory address that holds the exact location of the actual value in computer memory.
Q: What is the use of the ‘this’ keyword?
A: ‘This’ refers to the current class or object, as opposed to a global class or object.
Q: What is a virtual function?
A: A virtual function is a member of its class and can be overridden in derived classes.
Q: What is the ‘super’ keyword used for?
A: This is a special keyword that allows access to methods that have been overwritten.
Q: What are tokens?
A: Tokens are instructions recognized by the compiler that cannot be broken down in any way. Some examples of tokens are keywords, constants, identifiers, string literals, and operators.
This is, of course, not a complete list, and good working knowledge is still required to start in any field that uses object-oriented languages. These are just a few questions to jog your memory and prepare you for some tricky questions that potential employers may ask you.