+91 90691 39140 | +1 253 214 3115 | info@hub4tech.com | hub4tech

OOPs Interview Questions and Answers

What are the basic concepts of OOP?

The four basic concepts of OOP are:

  1. Abstraction
  2. Polymorphism
  3. Inheritance
  4. Encapsulation
What is OOPS?

OOPS is abbreviated as Object Oriented Programming system in which programs are considered as a collection of objects. Each object is nothing but an instance of a class.

What are properties and methods of a class?

Properties define the “nouns” of your classes. They let the programmer determine a look and feel of the object. For instance, if you have a class that defines a house, the class properties would describe the house’s color, size, and address. The class methods are the “verbs.” Methods define the actions carried out by your classes.

What is friend function?
  • Friend function is a friend of a class.
  • It is allowed to access Public, private or protected data of that class.
  • It can be declared anywhere in the class declaration
  • It doesn’t have any effect of access control keywords like private, public or protected.
What is function overloading?

Function overloading is defined as a normal function, but it has the ability to perform different tasks. It allowscreation of several methods with the same name which differ from each other by type of input and output of the function.

void add(int& a, int& b);
void add(double& a, double& b);
void add(struct bob& a, struct bob& b);

What are static functions?

Static functions and classes require no instantiation. It means that you can use these classes, functions, and parameters at-will without creating and instantiating the object. Static functions are beneficial when you need quick execution of functions that don’t need other parts of the containing class. You cannot use non-static classes with static functions.

What is dynamic or run time polymorphism?
  • It is also referred to as method overriding. Here, there can be two methods with same name and signature but different implementation.
  • The function here is resolved during run time rather than compile time.
What is a class?

A class is simply a representation of a type of object. It is the blueprint/ plan/ template that describe the details of an object.

What is private and public when defining methods or properties in classes?

The two major types of inheritance accessibility definitions are public and private. Private definitions restrict the method or property to the internal class. This means that external classes are not able to “see” the private definitions. You use these private methods and properties to manipulate data within the class. Public makes the methods and properties available to other classes. For instance, if you want to create a car class, you want other classes to be able to move the car. The car’s “move” method would be public, so other classes can move the car. However, you would not want other classes to be able to change aspects about the car’s engine. You would then keep engine properties private.

Can you give some examples of tokens?

Some of the examples of tokens are:

  • Keywords,
  • Identifiers,
  • Constants,
  • Operators,
  • Brackets,
  • Commas.
What is a pointer?

Pointers are typically used in C++, but they are also relevant in other programming languages. Pointers are the actual memory location of a value. Because a pointer is an actual memory physical location, when you change a value in a pointer, you change the value in memory so it is global. When you globally change a value, it changes for all classes, methods and any code that uses that value.

What is Encapsulation?
  • It is a technique to hide the properties and behaviours of an object.
  • The access is provided only as required.
  • It prevents other objects from altering or accessing the properties of an encapsulated object.
What is an abstract class?

An abstract class cannot be instantiated, but it can be inherited. This means that your inherited class can use the abstract class methods and properties, but the abstract class cannot be called directly. Abstract classes are good for defining global definitions for your inherited classes, so you only need to define these definitions once.

Explain method overriding.
  • When a subclass declares a method possessing similar arguments as a method declared by one of its superclass, method overriding takes place.
  • Using this technique, the behaviour specific to a particular subclass can be defined.
  • The methods marked public, final or static can not be overridden
What isfriend function?

Friend function is a friend of a class that is allowed to access to Public, private or protected data in that same class. If the function is defined outside the class cannot access such information.
Friend can be declared anywhere in the class declaration, and it cannot be affected by access control keywords like private, public or protected.

What is the “this” object?

The “this” reference refers to the current instance of the class. You typically use “this” to reference an internal property or method of the class. You will see “this” in various programming languages. Basically, “this” refers to the currently instantiated object.

What is avirtual function?

Virtual function is a member function ofclass and its functionality can be overridden in its derived class. This function can be implemented by using a keyword called virtual, and it can be given during function declaration.
Virtual function can be achieved in C++, and it can be achieved in C Languageby using function pointers or pointers to function.

Differentiate between abstraction and encapsulation.
  • Abstraction is design oriented while abstraction is implementation oriented.
  • The focus of abstraction is on the interface i.e. the outside view of the object while encapsulation prevents other objects or methods from looking into the properties and behaviour of that object.
What are manipulators?

Manipulators are the functions which can be used in conjunction with the insertion (<<) and extraction (>>) operators on an object. Examples are endl and setw.

What is instantiation?

Instantiation is how you create a class object. The class object is instantiated using the constructor whether that constructor has no parameters or several parameters. You need to instantiate a class before you can use it. After you instantiate your class, you can use its properties and methods. After you are finished with the class and it is out of scope, you use the class destructor to destroy it and remove it from memory.

What is Inheritance?
  • It is the process which allows the objects of one class to acquire the properties of objects of another class.
  • The class that inherits is called sub-class while the class from which the object is inherited is called superclass.
  • Inheritance helps in re-using the code and polymorphism.
What is Inline function?

Inline function is a technique used by the compilers and instructs to insert complete body of the function wherever that function is used in the program source code.

What is exception handling?

Exception handling is a type of error correction that traps “mistakes” in your code. You want users to come across issues in a graceful exception. This graceful exception traps errors, so the program doesn’t crash. The error correction is useful when a connection to a database occurs or you accidentally configure two values incorrectly. The error handling exception shows an error to the user and allows the user to continue using the program without it shutting down.

Define Destructor?

Destructor is a method which is automatically called when the object ismade ofscope or destroyed. Destructor name is also same asclass name but with the tilde symbol before the name.

What are parameters called by value versus reference?

When you pass parameters to your methods, you send the methods parameters by value by default. This means that the value of the past variable only changes within the function. When the function is finished executing, the value does not stay constant. However, when you pass a parameter by reference, you actually pass a pointer to the function. A pointer is a reference to a value in memory. When you manipulate values in memory, they are global, so not only change the value within the method, you also change the physical value in memory. When the method is finished executing, the value is also changed globally, so the value is changed permanently outside of the method.

Copyright ©2015 Hub4Tech.com, All Rights Reserved. Hub4Tech™ is registered trademark of Hub4tech Portal Services Pvt. Ltd.
All trademarks and logos appearing on this website are the property of their respective owners.