0% found this document useful (0 votes)
526 views4 pages

Object Oriented Programming Interview Cheatsheet

The document provides an overview of common object-oriented programming concepts and terminology. It defines key concepts like class, object, constructor, destructor, encapsulation, inheritance, polymorphism, and more. It also gives examples of these concepts in C++ code to illustrate how they are implemented in an object-oriented programming language.

Uploaded by

pratik
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
526 views4 pages

Object Oriented Programming Interview Cheatsheet

The document provides an overview of common object-oriented programming concepts and terminology. It defines key concepts like class, object, constructor, destructor, encapsulation, inheritance, polymorphism, and more. It also gives examples of these concepts in C++ code to illustrate how they are implemented in an object-oriented programming language.

Uploaded by

pratik
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 4

Object Oriented Programming Interview Cheatsheet

I got tired of all the interviews that ask you programming terminologies, so I compiled a cheatsheet
that covers common object oriented programming terminologies.

Object: An object can be anything in the world with attributes and behaviours that can be written
into a program.

Class: A class refers to a group of common objects with same attributes and methods.

Constructor: Method that creates an object from a class

Destructor: Method that deletes the object and frees up memory that the object once occupied

Encapsulation A mechanism to restrict access to some of the object’s components

Instantiation: Instantiation is an act of creating an object from a class.

Instance: An instance is the resulting object created from instantiating an object from a class.

Initialization: Initialization sets the default values for an object.

Method (a.k.a function): A method defines a particular behaviour of a class.

Inheritance: Inheritance refers to a phenomenon where a subclass borrows attributes and methods
from another class, namely a superclass.

Multiple inheritance: Multiple inheritance refers to the ability of a class to inherit attributes and
methods from more than one superclass.

Subclass (a.k.a child class): A subclass borrows attributes and methods from the superclass.

Superclass (a.k.a parent class): A superclass lends attributes and methods to subclass

Interface: An interface is a set of related methods which are not suitable to be included in any
classes.

Abstract class: An abstract class cannot create instances of itself.

Method overloading: Method overloading is the ability to create several methods with the same
name that has different input and output. For example, method called “size” in Ruby performs
differently for a string (returns length of the string) and an int value (returns the number of bytes
occupied by the integer).

Method overriding Method overriding is the ability of a subclass to replace a method that is already
provided by one of its superclasses with a more specific implementation.
OOPs Concepts in C++

BY CHAITANYA SINGH | FILED UNDER: LEARN C++

Object oriented programming is a way of solving complex problems by breaking them into smaller
problems using objects. Before Object Oriented Programming (commonly referred as OOP),
programs were written in procedural language, they were nothing but a long list of instructions. On
the other hand, the OOP is all about creating objects that can interact with each other, this makes it
easier to develop programs in OOP as we can understand the relationship between them.

Object Oriented Programming(OOP)

In Object oriented programming we write programs using classes and objects utilising features of
OOPs such as abstraction, encapsulation, inheritance and polymorphism

Class and Objects

A class is like a blueprint of data member and functions and object is an instance of class. For
example, lets say we have a class Car which has data members (variables) such as speed, weight,
price and functions such as gearChange(), slowDown(), brake() etc. Now lets say I create a object of
this class named FordFigo which uses these data members and functions and give them its own
values. Similarly we can create as many objects as we want using the blueprint(class).

//Class name is Car

class Car

//Data members

char name[20];

int speed;

int weight;

public:

//Functions

void brake(){

void slowDown(){

};

int main()

{
//ford is an object

Car ford;

Abstraction

Abstraction is a process of hiding irrelevant details from user. For example, When you send an sms
you just type the message, select the contact and click send, the phone shows you that the message
has been sent, what actually happens in background when you click send is hidden from you as it is
not relevant to you.

Encapsulation

Encapsulation is a process of combining data and function into a single unit like capsule. This is to
avoid the access of private data members from outside the class. To achieve encapsulation, we make
all data members of class private and create public functions, using them we can get the values from
these data members or set the value to these data members.

Inheritance

Inheritance is a feature using which an object of child class acquires the properties of parent class.

#include <iostream>

using namespace std;

class ParentClass {

//data member

public:

int var1 =100;

};

class ChildClass: public ParentClass {

public:

int var2 = 500;

};

int main(void) {

ChildClass obj;

Now this object obj can use the properties (such as variable var1) of ParentClass.

Polymorphism

Function overloading and Operator overloading are examples of polymorphism. Polymorphism is a


feature using which an object behaves differently in different situation.
In function overloading we can have more than one function with same name but different numbers,
type or sequence of arguments.

Polymorphism Example

#include <iostream>

using namespace std;

class Sum {

public:

int add(int num1,int num2){

return num1 + num2;

int add(int num1, int num2, int num3){

return num1 + num2 + num3;

};

int main(void) {

//Object of class Sum

Sum obj;

//This will call the second add function

cout<<obj.add(10, 20, 30)<<endl;

//This will call the first add function

cout<<obj.add(11, 22);

return 0;

Output:

60

33

You might also like