Tuesday, June 28, 2022

OOPS concepts

 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.


basic concepts of OOPS:

Abstraction

Encapsulation

Inheritance

Polymorphism


Class:

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

object:

An object is an instance of a class. It has its own state, behavior and identity.


Encapsulation:

Encapsulation is an attribute of an object, and it contains all data which id hidden. That hidden data can be restricted to the members of that class.

Levels are Public, private , Protected , Internal and Protected Internal.


Polymorphism:

Polymorphism is nothing but assigning behavior or value in a sub-class to something that was already declared in the main class. Simply polymorphism takes more than one form.


Inheritance:

Inheritance is a concept where one class shares the structure and behavior defined in another class. If Inhertiance applied to one class is called single inheritance and if it depends on multiple classes, then it is called multiple inheritance.


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.


Constructors:

A  constructor is a method used to  initialize  the state of  an object and it gets invoked at the time of object creation. Rules for constructor are 

Constructor Name should be the same as a class name 

A constructor must have no return type.

Destructor:

A destructor is a method  which is automatically called when the object is made of scope or destroyed. Destructor name is also same as class name but with the tilde symbol before the name.


Inline function:

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


Virtual function:

A virtual function is a member function of a class and is functionality can be overridden in its derived class. This function can be implemented by using a keyword called virtual an it can be given function declaration.

A virtual function can be declared using a token(virtual) in C++. It can be achieved in  C/PYTHON language by using function pointers or pointers to function.


Friend function 

A 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.


A friend can be declared  anywhere in the class declaration and it cannot be affected by access control keywords like private, public or protected.


Function  overloading:

Function overloading is a regular function, but it is assigned with multiple parameters. It allows the creation of several methods 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(doubles& a,  doubles& b);

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


Operator overloading:


Operator overloading is a function where different operators are appiled and depends on the arguments. Operator  -,* can be  used to pass through the function and it has its own precedence to execute.


Abstract class:

An abstract class is a class which cannot be instantiated.  Creation of an object is not possible with an abstract class, but it can be inherited. An abstract class can contain only an Abstract method. Java allows only abstract method in abstract class while other languages allow non-abstract method as well.

Ternary operator:

The ternary operator is said to be an operator which takes three arguments. Arguments and results are of different data types and it depends on the function. The ternary operator is also called a conditional operator.

Finalized method:

Finalized method helps to perform cleanup operations on the resources which are not currently used. Finalized method is protected and it is accessible only through this class or by a derived class.

Different types of arguments:

A parameter is a variable used during the declaration of the function or subroutine and arguments are passed to the function body and it should match with the parameter defined.

There are two types of arguments:

Call by value - Value passed will get modified only inside the function, and it returns the same value whatever it is passed into the function.

Call by reference - Value passed  will get  modified in both inside and outside the functions and it returns the same or different value.

































No comments:

Post a Comment