Library

OOPS Interview Questions and Answers for freshers & experience

Object Oriented Programming System (OOPS) has a high potential for earnings. In the US, as far back as in 2014, the Bureau of Labor Standards estimated that the average pay for an OOPS developer was a little over $80,000. An OOPS develop doesn’t need to interact with many other team members, because of which people can work from home, making this a profession to be chosen for those who want to bring about work-life balance.

This is a good time to be an OOPS developer. However, as with almost all other IT fields, it requires continuous learning from time to time to keep up with the growing changes in the area. BLS also estimates that OOPS has not been growing at a pace consistent with other domains of IT.

1st Round: OOPS Basic interview questions and answers:

Q1. What is OOPS?

Ans: OOPS is the short form for Object Oriented Programming System. In this system, programs are considered a collection of objects. Each object is an instance of a class.

Q2. What are the basic concepts of OOPS?

Ans: These are some of them:

1.  Abstraction.

2.  Polymorphism.

3.  Inheritance.

4.  Encapsulation.

Q3. How do you define a class?

Ans: A class is just nothing other than being a representation of a type of object. It is what you may call the blueprint for describing the details of an object.

Q4. Define an object

Ans: An instance of a class is an object. It comes with its own state, behavior, and identity.

Q5. What is your understanding of Encapsulation?

Ans: Encapsulation is an attribute of an object. All data that is hidden is contained in it. That hidden data can be restricted to the members of that class. This is done through the following levels: public, Protected, Private, Internal and Protected Internal.

Q6. Explain Polymorphism in OOPS?

Ans: Polymorphism is a method by which the behavior or value is assigned in a subclass to something that was already declared in the main class. It takes more than one form, and hence the name.

Q7. Describe Inheritance?

Ans: In the concept of inheritance, one class shares the structure and behavior defined in another class. Inheritance that is applied on one class is called Single Inheritance. When it is done on multiple classes, it is called multiple Inheritance.

Q8. Define manipulators

Ans: Manipulators are the functions which can be used in combination with the insertion (<<) and extraction (>>) operators on an object. endl and setw are some of the examples of manipulators.

Q9. What is a constructor?

Ans: This is a method by which the the state of an object is initialized. A constructor is invoked when objects are being created. These are the rules for constructors:

  • The Constructor name and the class name should be the same
  • It should have no return type.

Q10. What is a Destructor

Ans: A destructor is a method that gets called out automatically when the object is made of scope or destroyed. The destructor has the same name as the class but has the tilde symbol before the name.

Q11. Define an Inline function

Ans: Compilers use this technique to insert complete body of the function to instruct wherever that function is used in the program source code.

Q12. How do you define a virtual function?

Ans: Being member function of a class, a virtual function and its functionality can be overridden in its derived class. This is done using a keyword called virtual, and it can be given during function declaration.

Q13. Explain a friend function

Ans: This is a friend of a class that is allowed to access to Public, private or protected data in that same class. This is used when the function defined outside the class cannot access such information. Friend can be declared anywhere in the class declaration. Access control keywords like private, public or protected don’t affect it.

Q14. Define function overloading

Ans: Function overloading is a normal function, but it can perform different tasks. One of these is to allow several methods to be created with the same name, which differ from each other by the type of input and output of the function.

Example

void add(int& a, int& b);

void add(double& a, double& b);

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

Q15. What is operator overloading?

Ans: Operator overloading is a function in which different operators are applied. It depends on the arguments. Operator,-,* can be used to pass through the function, and it has its own precedence to execute

Q16. What is an abstract class?

 Ans: An abstract class is a class which cannot be instantiated. While an abstract class cannot create an object; it can inherit one. An abstract class can contain only Abstract method. While Java allows only abstract method in abstract class; other languages allow non-abstract method as well.

Q17. What is a ternary operator?

Ans: Also called a conditional operator; the ternary operator is an operator which takes three arguments. In ternary operators, arguments and results are of different data types, and it depends on the function.

Q18. What is the finalize method used for?

Ans: The finalize method is used for cleanup operations on the resources which are not currently used. Being protected, the finalize method is accessible only through this class or by a derived class.

Q19. Which are the different types of arguments?

Ans: There are two types of Arguments.

  • Call by Value – In this kind of argument, the value passed gets modified only inside the function, and it returns the same value whenever it is passed it into the function.
  • Call by Reference – This is when the Value passed gets modified both inside and outside the functions and it returns the same or different value.

Q20. What is the super keyword in OOPS?

Ans: Super keyword helps to invoke the overridden method which overrides one of its superclass methods. This keyword allows to access overridden methods and also to access hidden members of the superclass.

It also forwards a call from a constructor to a constructor in the superclass.

Q21. Explain method overriding

Ans: Method overriding is a feature by which a subclass to provide the implementation of a method that overrides in the main class is allowed. This overrides the implementation in the superclass by providing the same method name, same parameter and same return type.

Q22. What is an interface?

Ans: This is how we understand an interface: It is a collection of an abstract method. If the class implements an inheritance, it thereby inherits all the abstract methods of an interface.

Q23.  Explain exception handling

Ans: An exception is any event that takes place while the program is being executed. Exceptions can be of either Runtime or Error exceptions types. Exception handling mechanisms like try, catch and throw keywords are used to handle exceptions.

Q24. Describe tokens

Ans: The token is recognized by a compiler, and it cannot be broken down into component elements. Some of the examples of tokens are keywords, identifiers, constants, string literals, operators and punctuation characters such as brackets, commas, braces and parentheses.

Q25. Differentiate between overloading and overriding

Ans: While overloading is a static binding; Overriding is a dynamic binding. Overloading is the same method with different arguments, and it may or may not return the same value in the same class itself.

Overriding, on the other hand, is the same method names with same arguments and return types associated with the class and its child class.

Q26. Differentiate between class and an object?

Ans: An object is an instance of a class. While objects hold multiple information; classes don’t. Properties and functions can be defined in class and can be used by the object. Also, while a class can have sub-classes, an object doesn’t have sub-objects.

Q27. What is an abstraction?

Ans: Abstraction is a very useful feature of OOPS that shows only the necessary details to the client of an object. That is, it shows only the details required for an object and not the inner constructors, of an object. Example – When you want to switch television on, it is not necessary to show all the functions of TV. Only whatever you want to see on the screen will be showed by using abstract class.

Q28. What are access modifiers?

Ans: Access modifiers are features that determine the scope of the method or variables that can be accessed from other various objects or classes. These are the five types of access modifiers:

  • Private.
  • Protected.
  • Public.
  • Friend.
  • Protected Friend.

Q29. Defined sealed modifiers?

Ans: Sealed modifiers are the access modifiers that are used where the methods cannot inherit them. Sealed modifiers can also be applied to properties, events, and methods, but cannot be applied to static members.

 Q30. It is possible to call the base method without creating an instance? If so, how?

Ans: It is possible. This is done using the Static method.

Q31. How does new differ from override?

Ans: While the new modifier instructs the compiler to use the new implementation instead of the base class function; the Override modifier helps to override the base class function.

Q32. Describe the types of constructors?

Ans: These are the three types of constructors:

– Default Constructor – With no parameters.

– Parametric Constructor – With Parameters. Create a new instance of a class and pass arguments simultaneously.

– Copy Constructor – Creates a new object as a copy of an existing object.

Q33. What are early and late binding?

Ans: Early binding refers to the assignment of values to variables during design time, while late binding refers to the assignment of values to variables during run time.

Q34. What is ‘THIS’ pointer?

Ans: THIS pointer refers to the current object of a class. The THIS keyword is used as a pointer for differentiating between the current object with the global object. Essentially, it refers to the current object.

Q35. How does a structure differ from a class?

Ans: While the structure default access type is public; the class access type is private. Also, while the structure is used for grouping data; class can be used for grouping data and methods. Structures are exclusively used for data, and don’t require strict validation, but classes are used to encapsulate and inherit data, an activity that requires strict validation.

Q36. Which is the default access modifier in a class?

Ans: The default access modifier of a class is Private. This is set by default.

Q37. Describe a pure virtual function

Ans: This is what a pure virtual function is: it is a function which can be overridden in the derived class but cannot be defined. A virtual function can be declared as Pure by using the operator =0.

Q38. Mention the operators that cannot be overloaded

Ans: These are the operators that cannot be overloaded -.

1.  Scope Resolution (:: )

2.  Member Selection (.)

3.  Member selection through a pointer to function (.*)

Q39. Describe dynamic or run time polymorphism?

Ans: Dynamic or Run time polymorphism, also known as method overriding, is a process in which a call to an overridden function is resolved during run time, and not at the compile time. This entails having two or more methods with the same name and signature but with different implementation.

Q40. Are parameters required for constructors?

Ans: No. They are not.

Q41. Explain a copy constructor

Ans: The copy constructor is a special constructor with which a new object is created as a copy of an existing object. It is possible for only one copy constructor that can be either defined by the user or the system to be present.

Q42. What does the keyword virtual represented in the method definition mean?

Ans: It means that the method can be overridden.

Q43. Can static method use non-static members?

Ans: No

Q44. What is a base class, sub class, and super class?

Ans: The base class is the most generalized class, and it is said to be a root class.

A Sub class is a class that inherits from one or more base classes.

The superclass is the parent class from which another class inherits.

Q45. What are static and dynamic binding?

Ans: Binding is the means of associating a name with the class. In static binding, the name can be associated with the class during compilation time, which is why it also goes by the name of early Binding.

Dynamic binding, being a binding method in which name can be associated with the class during execution time, is also called as Late Binding.

Q46. How many instances can be created for an abstract class?

Ans: Zero instances can be created for an abstract class.

Q47. Which keyword can be used for overloading?

Ans: Operator keyword.

Q48. Mention the default access specifier in a class definition

Ans: It is the private access specifier used in a class definition.

Q49. Which OOPS concept is used as reuse mechanism?

Ans: Inheritance

Q50. Name the OOPS concept that exposes only necessary information to the calling functions

Ans: It is encapsulation

HR Round:

Describe your experience of having worked with OOPS

Are you comfortable working independently or are you a team player?

What are the ways in which you think OOPS can make a development to software development?

How important to you think the role of OOPS is in today’s industry?

How do you plan to override the challenges of being an OOPS developer?

Conclusion:

OOPS is going to be around for as long as all other mainstream domains of programming are going to. OOPS requires a good level of skill and knowledge as well as the ability to work independently. Many OOPS developers prefer to work independently, which means that they could work either for companies or work independently as consultants. This opens up many ways by which they can create a strong income stream. We have tried our best to answer some of the common queries relating to OOPS. We are confident you will find this set useful.