Home OOPS Interview Questions and Answers

OOPS Interview Questions and Answers

What is meant by Object Oriented Programming? OOP is a method of programming in which programs are organised as cooperative collections of objects. Each object is an instance of a class and each class belong to a hierarchy.
What is a Class?
Class is a template for a set of objects that share a common structure and a common behaviour.
What is an Object? Object is an instance of a class. It has state,behaviour and identity. It is also called as an instance of a class
What is an Instance? An instance has state, behaviour and identity. The structure and behaviour of similar classes are defined in their common class. An instance is also called as an object.
What are the core OOP’s concepts?
Abstraction, Encapsulation,Inheritance and Polymorphism are the core OOP’s concepts
What is meant by abstraction? Abstraction defines the essential characteristics of an object that distinguish it from all other kinds of objects. Abstraction provides crisply-defined conceptual boundaries relative to the perspective of the viewer. Its the process of focussing on the essential characteristics of an object. Abstraction is one of the fundamental elements of the object model.
What is meant by Encapsulation?
Encapsulation is the process of compartmentalising the elements of an abtraction that defines the structure and behaviour. Encapsulation helps to separate the contractual interface of an abstraction and implementation.
What is meant by Inheritance?
Inheritance is a relationship among classes, wherein one class shares the structure or behaviour defined in another class. This is called Single Inheritance. If a class shares the structure or behaviour from multiple classes, then it is called Multiple Inheritance. Inheritance defines “is-a” hierarchy among classes in which one subclass inherits from one or more generalised superclasses.
What is meant by Polymorphism? Polymorphism literally means taking more than one form. Polymorphism is a characteristic of being able to assign a different behavior or value in a subclass, to something that was declared in a parent class.
What is an Abstract Class? Abstract class is a class that has no instances. An abstract class is written with the expectation that its concrete subclasses will add to its structure and behaviour, typically by implementing its abstract operations.
What is an Interface?
Interface is an outside view of a class or object which emphaizes its abstraction while hiding its structure and secrets of its behaviour
What is a base class?
Base class is the most generalised class in a class structure. Most applications have such root classes. In Java, Object is the base class for all classes.
What is a subclass?
Subclass is a class that inherits from one or more classes
What is a superclass? superclass is a class from which another class inherits
What is a constructor?
Constructor is an operation that creates an object and/or initialises its state
What is a destructor? Destructor is an operation that frees the state of an object and/or destroys the object itself.
What is meant by Binding? Binding denotes association of a name with a class.
What is meant by static binding? Static binding is a binding in which the class association is made during compile time. This is also called as Early binding
What is meant by Dynamic binding? Dynamic binding is a binding in which the class association is not made until the object is created at execution time. It is also called as Late binding.
What is meant by Persistence?
Persistence is the property of an object by which its existence transcends space and time.
How is polymorphism acheived Inheritance, Overloading and Overriding are used to acheive Polymorphism
Explain the advantages of Encapsulation in Object Oriented Programming Languages Benefits of Encapsulation in oops:
Encapsulation makes it possible to separate an objects implementation from its behavior to restrict access to its internal data. This restriction allows certain details of an objects behavior to be hidden. It allows us to create a “black box” and protects an objects internal state from corruption by its clients.
Encapsulation is a technique for minimizing interdependencies among modules by defining a strict external interface. This way, internal coding can be changed without affecting the interface, so long as the new implementation supports the same (or upwards compatible) external interface. So encapsulation prevents a program from becoming so interdependent that a small change has massive ripple effects.The implementation of an object can be changed without affecting the application that uses it for: Improving performance, fix a bug, consolidate code or for porting.
What is Encapsulation in Object Oriented Programming (OOPS) Languages? Encapsulation is the procedure of covering up of data and functions into a single unit. Encapsulation (also information hiding) consists of separating the external aspects of an object which are accessible to other objects, from the internal implementation details of the object, which are hidden from other objects.A process, encapsulation means the act of enclosing one or more items within a (physical or logical) container (Class).Object-oriented programming is based on encapsulation. When an objects state and behavior are kept together, they are encapsulated. That is, the data that represents the state of the object and the methods (Functions and Subs) that manipulate that data are stored together as a cohesive unit.The object takes requests from other client objects, but does not expose its the details of its data or code to them. The object alone is responsible for its own state, exposing public messages for clients, and declaring private methods that make up its implementation. The client depends on the (hopefully) simple public interface, and does not know about or depend on the details of the implementation.

For example, a HashTable object will take get() and set() requests from other objects, but does not expose its internal hash table data structures or the code strategies that it uses

What is a Virtual Functions in class?
A virtual function is a member function of the base class and which is redefined by the derived class. When a derived class inherits the class containing the virtual function, it has ability to redefine the virtual functions.A virtual function has a different functionality in the derived class according to the requirement. The virtual function within the base class provides the form of the interface to the function. Virtual function implements the philosophy of one interface and multiple methods (polymorphism).The virtual functions are resolved at the run time. This is called dynamic binding. The functions which are not virtual are resolved at compile time which is called static binding. A virtual function is created using the keyword virtual which precedes the name of the function.
What are the Limitations and Restrictions of Interface The essential idea to remember is that an interface never contains any implementation. The following restrictions and imitations are natural consequences of this:You’re not allowed any fields in an interface, not even static ones. A field is an implementation of an object attribute.You’re not allowed any constructors in an interface. A constructor contains the statements used to initialize the fields in an object, and an interface does not contain any fields!You’re not allowed a destructor in an interface. A destructor contains the statements used to destroy an object instance.

You cannot supply an access modifier. All methods in an interface are implicitly public.

You cannot nest any types (enums, structs, classes, interfaces, or delegates) inside an interface

Explain some characteristics of inheritance. A class inherits the members of its direct base class. Inheritance means that a class implicitly contains all members of its direct base class, except for the constructors and destructors of the base class.Some important aspects of inheritance are:Inheritance is transitive. If C is derived from B, and B is derived from A, then C inherits the members declared in B as well as the members declared in AA derived class extends its direct base class. A derived class can add new members to those it inherits, but it cannot remove the definition of an inherited member.

Constructors and destructors are not inherited, but all other members are, regardless of their declared accessibility. However, depending on their declared accessibility, inherited members might not be accessible in a derived class.

A derived class can hide inherited members by declaring new members with the same name or signature. Note however that hiding an inherited member does not remove that member; it merely makes that member inaccessible in the derived class.

An instance of a class contains a set of all instance fields declared in the class and its base classes, and an implicit conversion exists from a derived class type to any of its base class types. Thus, a reference to an instance of some derived class can be treated as a reference to an instance of any of its base classes.

A class can declare virtual methods, properties, and indexers, and derived classes can override the implementation of these function members. This enables classes to exhibit polymorphic behavior wherein the actions performed by a function member invocation varies depending on the run-time type of the instance through which that function member is invoked.

What are the various elements of OOP? Various elements of OOP are:Object
Class
Method
Encapsulation
Information Hiding
Inheritance
Polymorphism
Various elements of OOP are:Object
Class
Method
Encapsulation
%0