What is Object Oriented Programming ?
Object Oriented Programming āύāĻžāĻŽā§ āĻĒāϰāĻŋāĻāĻŋāϤ āĻāĻāĻāĻŋ āĻāĻŽā§āĻĒāĻŋāĻāĻāĻžāϰ āĻĒā§āϰā§āĻā§āϰāĻžāĻŽāĻŋāĻ āϝāĻž āϝā§āĻā§āϤāĻŋāϰ āĻĒāϰāĻŋāĻŦāϰā§āϤ⧠āĻĄā§āĻāĻž āĻŦāĻž āĻŦāϏā§āϤā§āϰ āĻāĻžāϰāĻĒāĻžāĻļā§ āϏāĻĢā§āĻāĻāϝāĻŧā§āϝāĻžāϰā§āϰ āϏā§āĻĨāĻžāĻĒāϤā§āϝāĻā§ āϏāĻžāĻāĻžāϝāĻŧāĨ¤ āĻāĻāĻāĻŋ āĻŦāϏā§āϤ⧠āĻšāϞ āύāĻŋāϰā§āĻĻāĻŋāώā§āĻ āĻŦā§āĻļāĻŋāώā§āĻā§āϝ āĻāĻŦāĻ āĻāĻāϰāĻŖ āϏāĻš āĻāĻāĻāĻŋ āϤāĻĨā§āϝ āĻā§āώā§āϤā§āϰāĨ¤
Object Oriented Programming āĻ āĻĒā§āϰāϝāĻŧā§āĻāύā§āϝāĻŧ āϝā§āĻā§āϤāĻŋāϰ āĻā§āϝāĻŧā§ āĻĒā§āϰā§āĻā§āϰāĻžāĻŽāĻžāϰāϰāĻž āϝ⧠āĻŦāϏā§āϤā§āĻā§āϞāĻŋ āĻĒāϰāĻŋāĻāĻžāϞāύāĻž āĻāϰāϤ⧠āĻāĻžāϝāĻŧ āϤāĻžāϰ āĻāĻĒāϰ āĻŦā§āĻļāĻŋ āĻā§āϰ āĻĻā§āϝāĻŧāĨ¤ āĻŦāĻĄāĻŧ, āĻĒāϰāĻŋāĻļā§āϞāĻŋāϤ āĻāĻŦāĻ āϏāĻā§āϰāĻŋāϝāĻŧāĻāĻžāĻŦā§ āĻāĻĒāĻĄā§āĻ āĻāϰāĻž āĻŦāĻž āϰāĻā§āώāĻŖāĻžāĻŦā§āĻā§āώāĻŖ āĻāϰāĻž āĻĒā§āϰā§āĻā§āϰāĻžāĻŽāĻā§āϞāĻŋ āĻāύā§āύāϝāĻŧāύā§āϰ āĻāĻ āĻĒāĻĻā§āϧāϤāĻŋāϰ āĻāύā§āϝ āĻāĻĒāϝā§āĻā§āϤāĨ¤ āĻāϰ āĻŽāϧā§āϝ⧠āĻŽā§āĻŦāĻžāĻāϞ āĻ ā§āϝāĻžāĻĒā§āϞāĻŋāĻā§āĻļāύā§āϰ āĻĒāĻžāĻļāĻžāĻĒāĻžāĻļāĻŋ āύāĻāĻļāĻž āĻāĻŦāĻ āĻā§āĻĒāĻžāĻĻāύ āϏāĻĢā§āĻāĻāϝāĻŧā§āϝāĻžāϰ āĻ āύā§āϤāϰā§āĻā§āĻā§āϤ āϰāϝāĻŧā§āĻā§āĨ¤ āĻāĻĻāĻžāĻšāϰāĻŖāϏā§āĻŦāϰā§āĻĒ, āĻāĻāĻĒāĻŋ āϏāĻŋāϏā§āĻā§āĻŽ āϏāĻŋāĻŽā§āϞā§āĻļāύ āϏāĻĢā§āĻāĻāϝāĻŧā§āϝāĻžāϰ āϤā§āϰāĻŋāϤ⧠āĻĒā§āϰāϝāĻŧā§āĻ āĻāϰāĻž āϝā§āϤ⧠āĻĒāĻžāϰā§āĨ¤ [A computer programming paradigm known as object-oriented programming (OOP) arranges the architecture of software around data or objects rather than functions and logic. An object is a data field with particular characteristics and behavior.
OOP places more emphasis on the objects that programmers desire to manipulate than on the logic necessary to do so. Large, sophisticated, and actively updated or maintained programs are a good fit for this method of development. This encompasses mobile applications as well as design and production software. OOP, for instance, can be applied to manufacturing system simulation software.]
how is object-oriented programming structured?
The following are some of the components, or building pieces, of object-oriented programming:
Classes: User-defined data types called classes serve as the building blocks for specific objects, attributes, and methods[āĻŦā§āϝāĻŦāĻšāĻžāϰāĻāĻžāϰā§-āϏāĻāĻā§āĻāĻžāϝāĻŧāĻŋāϤ āĻĄā§āĻāĻž āĻĒā§āϰāĻāĻžāϰāĻā§āϞāĻŋ āϝāĻžāĻā§ āĻā§āϞāĻžāϏ āĻŦāϞāĻž āĻšāϝāĻŧ āϤāĻž āύāĻŋāϰā§āĻĻāĻŋāώā§āĻ āĻŦāϏā§āϤā§, āĻŦā§āĻļāĻŋāώā§āĻā§āϝ āĻāĻŦāĻ āĻĒāĻĻā§āϧāϤāĻŋāϰ āĻāύā§āϝ āĻŦāĻŋāϞā§āĻĄāĻŋāĻ āĻŦā§āϞāĻ āĻšāĻŋāϏāĻžāĻŦā§ āĻāĻžāĻ āĻāϰā§āĨ¤]
Objects: Objects are instances of a class that were generated using data that was precisely defined. Objects can be an abstract concept or a real-world thing. The description is the only item that is first defined when a class is created.[āĻ
āĻŦāĻā§āĻā§āĻāĻā§āϞāĻŋ āĻāĻŽāύ āĻāĻāĻāĻŋ āĻļā§āϰā§āĻŖā§āϰ āĻāĻĻāĻžāĻšāϰāĻŖ āϝāĻž āϏāĻ āĻŋāĻāĻāĻžāĻŦā§ āϏāĻāĻā§āĻāĻžāϝāĻŧāĻŋāϤ āĻĄā§āĻāĻž āĻŦā§āϝāĻŦāĻšāĻžāϰ āĻāϰ⧠āϤā§āϰāĻŋ āĻāϰāĻž āĻšāϝāĻŧā§āĻāĻŋāϞāĨ¤ āĻŦāϏā§āϤā§āĻā§āϞāĻŋ āĻāĻāĻāĻŋ āĻŦāĻŋāĻŽā§āϰā§āϤ āϧāĻžāϰāĻŖāĻž āĻŦāĻž āĻŦāĻžāϏā§āϤāĻŦ-āĻāĻāϤā§āϰ āĻāĻŋāύāĻŋāϏ āĻšāϤ⧠āĻĒāĻžāϰā§āĨ¤ āĻŦāϰā§āĻŖāύāĻž āĻšāϞ āĻāĻāĻŽāĻžāϤā§āϰ āĻāĻāĻā§āĻŽ āϝāĻž āĻĒā§āϰāĻĨāĻŽ āϏāĻāĻā§āĻāĻžāϝāĻŧāĻŋāϤ āĻāϰāĻž āĻšāϝāĻŧ āϝāĻāύ āĻāĻāĻāĻŋ āĻļā§āϰā§āĻŖā§ āϤā§āϰāĻŋ āĻāϰāĻž āĻšāϝāĻŧāĨ¤]
Methods: Methods are described as internal class functions that explain an object’s behaviors. The first line of code in every method seen in class declarations is a reference to an instance object. Additionally, an object’s internal functions are referred to as instance methods. Programmers utilize techniques to make code reusable or to keep functionality contained within a single object at a time.[āĻŽā§āĻĨāĻĄāĻā§āϞāĻŋ āĻ āĻā§āϝāύā§āϤāϰā§āĻŖ āĻļā§āϰā§āĻŖā§ āĻĢāĻžāĻāĻļāύ āĻšāĻŋāϏāĻžāĻŦā§ āĻŦāϰā§āĻŖāύāĻž āĻāϰāĻž āĻšāϝāĻŧ āϝāĻž āĻā§āύāĻ āĻŦāϏā§āϤā§āϰ āĻāĻāϰāĻŖ āĻŦā§āϝāĻžāĻā§āϝāĻž āĻāϰā§āĨ¤ āĻļā§āϰā§āĻŖā§ āĻā§āώāĻŖāĻžāϝāĻŧ āĻĻā§āĻāĻž āĻĒā§āϰāϤāĻŋāĻāĻŋ āĻĒāĻĻā§āϧāϤāĻŋāϤ⧠āĻā§āĻĄā§āϰ āĻĒā§āϰāĻĨāĻŽ āϞāĻžāĻāύāĻāĻŋ āĻāĻāĻāĻŋ āĻāύāϏā§āĻā§āϝāĻžāύā§āϏ āĻ āĻŦāĻā§āĻā§āĻā§āϰ āĻāĻāĻāĻŋ āϰā§āĻĢāĻžāϰā§āύā§āϏāĨ¤ āĻāĻĒāϰāύā§āϤā§, āĻāĻāĻāĻŋ āĻŦāϏā§āϤā§āϰ āĻ āĻā§āϝāύā§āϤāϰā§āĻŖ āĻĢāĻžāĻāĻļāύ āĻāĻĻāĻžāĻšāϰāĻŖ āĻĒāĻĻā§āϧāϤāĻŋ āĻšāĻŋāϏāĻžāĻŦā§ āĻāϞā§āϞā§āĻ āĻāϰāĻž āĻšāϝāĻŧāĨ¤ āĻĒā§āϰā§āĻā§āϰāĻžāĻŽāĻžāϰāϰāĻž āĻā§āĻĄāĻā§ āĻĒā§āύāϰāĻžāϝāĻŧ āĻŦā§āϝāĻŦāĻšāĻžāϰāϝā§āĻā§āϝ āĻāϰāϤ⧠āĻŦāĻž āĻāĻāĻŦāĻžāϰ⧠āĻāĻāĻāĻŋ āĻŦāϏā§āϤā§āϰ āĻŽāϧā§āϝ⧠āĻāĻžāϰā§āϝāĻāĻžāϰāĻŋāϤāĻž āϰāĻžāĻāϤ⧠āĻā§āĻļāϞāĻā§āϞāĻŋ āĻŦā§āϝāĻŦāĻšāĻžāϰ āĻāϰā§āĨ¤]
Attribute: The class template defines attributes, which stand in for an object’s state. Data will be kept in the attributes field of objects. Class characteristics are the property of the class. [āĻā§āϞāĻžāϏ āĻā§āĻŽāĻĒā§āϞā§āĻ āĻŦā§āĻļāĻŋāώā§āĻā§āϝāĻā§āϞāĻŋ āϏāĻāĻā§āĻāĻžāϝāĻŧāĻŋāϤ āĻāϰā§, āϝāĻž āĻāĻāĻāĻŋ āĻŦāϏā§āϤā§āϰ āĻ āĻŦāϏā§āĻĨāĻžāϰ āĻāύā§āϝ āĻĻāĻžāĻāĻĄāĻŧāĻžāϝāĻŧāĨ¤ āĻĄā§āĻāĻž āĻ āĻŦāĻā§āĻā§āĻā§āϰ āĻ ā§āϝāĻžāĻā§āϰāĻŋāĻŦāĻŋāĻāĻ āĻĢāĻŋāϞā§āĻĄā§ āϰāĻžāĻāĻž āĻšāĻŦā§āĨ¤ āĻļā§āϰā§āĻŖā§ āĻŦā§āĻļāĻŋāώā§āĻā§āϝ āĻšāϞ āĻļā§āϰā§āĻŖā§āĻāĻŋāϰ āĻŦā§āĻļāĻŋāώā§āĻā§āϝāĨ¤]
Main principle Of Object Oriented Programming

Encapsulation
āĻāĻ āϧāĻžāϰāĻŖāĻž āĻ āύā§āϏāĻžāϰā§, āϏāĻŽāϏā§āϤ āĻĒā§āϰāϝāĻŧā§āĻāύā§āϝāĻŧ āϤāĻĨā§āϝ āĻāĻāĻāĻŋ āĻāĻāĻā§āĻŽā§āϰ āĻāĻŋāϤāϰ⧠āϰāĻžāĻāĻž āĻšāϞ⧠āĻļā§āϧā§āĻŽāĻžāϤā§āϰ āύāĻŋāϰā§āĻĻāĻŋāώā§āĻ āϤāĻĨā§āϝ āĻĒā§āϰāĻāĻžāĻļ āĻāϰāĻž āĻšāϝāĻŧāĨ¤ āĻĒā§āϰāϤāĻŋāĻāĻŋ āĻŦāϏā§āϤā§āϰ āĻŦāĻžāϏā§āϤāĻŦāĻžāϝāĻŧāύ āĻāĻŦāĻ āĻ āĻŦāϏā§āĻĨāĻž āĻāĻāĻāĻŋ āĻŽāύā§āύā§āϤ āĻā§āϞāĻžāϏā§āϰ āĻāĻŋāϤāϰ⧠āĻā§āĻĒāύ⧠āϰāĻžāĻāĻž āĻšāϝāĻŧāĨ¤ āĻāĻ āĻā§āϞāĻžāϏāĻāĻŋ āĻ āύā§āϝ āĻŦāϏā§āϤā§āϰ āĻāĻžāĻā§ āĻ ā§āϝāĻžāĻā§āϏā§āϏāϝā§āĻā§āϝ āύāϝāĻŧ, āĻŦāĻž āϤāĻžāĻĻā§āϰ āĻāĻāĻŋ āĻĒāϰāĻŋāĻŦāϰā§āϤāύ āĻāϰāĻžāϰ āĻā§āώāĻŽāϤāĻž āύā§āĻāĨ¤ āĻļā§āϧā§āĻŽāĻžāϤā§āϰ āĻĒāĻžāĻŦāϞāĻŋāĻ āĻĢāĻžāĻāĻļāύ āĻŦāĻž āĻĒāĻĻā§āϧāϤāĻŋāϰ āĻāĻāĻāĻŋ āϏā§āĻŽāĻŋāϤ āϏā§āĻ āĻāϰ āĻĻā§āĻŦāĻžāϰāĻž āĻ ā§āϝāĻžāĻā§āϏā§āϏ āĻŦāĻž āĻĒāϰāĻŋāĻŦāϰā§āϤāύ āĻāϰāĻž āϝā§āϤ⧠āĻĒāĻžāϰā§āĨ¤ āĻāĻ āĻŦā§āĻļāĻŋāώā§āĻā§āϝā§āϰ āϏāĻžāĻĨā§ āĻĄā§āĻāĻž āĻā§āĻĒāύ āĻāϰāĻž āĻ ā§āϝāĻžāĻĒā§āϞāĻŋāĻā§āĻļāύā§āϰ āύāĻŋāϰāĻžāĻĒāϤā§āϤāĻž āĻŦāĻžāĻĄāĻŧāĻžāϝāĻŧ āĻāĻŦāĻ āĻ āϏāĻžāĻŦāϧāĻžāύāϤāĻžāĻŦāĻļāϤ āĻĄā§āĻāĻž āĻā§āώāϤāĻŋ āĻĒā§āϰāϤāĻŋāϰā§āϧ āĻāϰā§āĨ¤ [According to this idea, only certain information is exposed while all essential information is kept inside an item. Each object’s implementation and state are kept secretly inside a designated class. This class is not accessible to other objects, nor do they have the power to modify it. Only a limited set of public functions or methods can be called by them. Data concealing with this feature enhances application security and prevents inadvertent data damage.]
Abstraction
āĻ āĻŦāĻā§āĻā§āĻāĻā§āϞāĻŋ āϝ⧠āĻā§āύāĻ āĻŦāĻšāĻŋāϰāĻžāĻāϤ āĻŦāĻžāϏā§āϤāĻŦāĻžāϝāĻŧāύ āĻāϰāĻž āĻā§āĻĄāĻā§ āĻā§āĻĒāύ āĻāϰ⧠āĻāĻŦāĻ āĻā§āĻŦāϞāĻŽāĻžāϤā§āϰ āĻ āĻā§āϝāύā§āϤāϰā§āĻŖ āĻĒā§āϰāĻā§āϰāĻŋāϝāĻŧāĻžāĻā§āϞāĻŋ āĻĒā§āϰāĻāĻžāĻļ āĻāϰ⧠āϝāĻž āĻ āύā§āϝāĻžāύā§āϝ āĻŦāϏā§āϤā§āϰ āĻŦā§āϝāĻŦāĻšāĻžāϰā§āϰ āĻāύā§āϝ āĻĒā§āϰāϝāĻŧā§āĻāύā§āϝāĻŧāĨ¤ Derived class āĻāϰ functionality āĻā§ āĻŦāĻžāĻĄāĻŧāĻžāύ⧠āϝā§āϤ⧠āĻĒāĻžāϰā§āĨ¤ āĻāĻ āϧāĻžāϰāĻŖāĻžāĻāĻŋ āĻĄā§āĻā§āϞāĻĒāĻžāϰāĻĻā§āϰ āĻāύā§āϝ āĻĒāϰ⧠āĻāĻŋāĻā§ āϝā§āĻ āĻāϰāϤ⧠āĻŦāĻž āĻāĻĒāĻĄā§āĻ āĻāϰāϤ⧠āϏāĻžāĻšāĻžāϝā§āϝ āĻāϰā§āĨ¤ [Objects conceal any extraneous implementation code and only expose internal mechanisms that are necessary for the use of other objects. The functionality of the derived class can be increased. This idea can make it simpler for developers to add or update something later.]
Inheritance
āĻāĻāĻāĻŋ āĻā§āϞāĻžāϏ āĻĨā§āĻā§ āĻ āύā§āϝ āĻā§āϞāĻžāϏ⧠āĻŦā§āĻļāĻŋāώā§āĻā§āϝ āĻ āĻŦā§āĻļāĻŋāώā§āĻā§āϝ āĻāĻšāϰāĻŖā§āϰ āĻā§āώāĻŽāϤāĻžāĻā§ Inheritance āĻŦāϞāĻž āĻšāϝāĻŧāĨ¤ āĻ āĻŦāĻā§āĻā§āĻ-āĻāϰāĻŋāϝāĻŧā§āύā§āĻā§āĻĄ āĻĒā§āϰā§āĻā§āϰāĻžāĻŽāĻŋāĻāϝāĻŧā§āϰ (Object Oriented Programming)āĻ āύā§āϝāϤāĻŽ āĻā§āϰā§āϤā§āĻŦāĻĒā§āϰā§āĻŖ āĻŦā§āĻļāĻŋāώā§āĻā§āϝ āĻšāϞ InheritanceāĨ¤ Inheritance āĻšāϞ āĻāĻŽāύ āĻāĻāĻāĻŋ āĻŦā§āĻļāĻŋāώā§āĻā§āϝ āĻŦāĻž āĻĒā§āϰāĻā§āϰāĻŋāϝāĻŧāĻž āϝā§āĻāĻžāύ⧠āĻŦāĻŋāĻĻā§āϝāĻŽāĻžāύ āĻā§āϞāĻžāϏāĻā§āϞāĻŋ(Existing class) āĻĨā§āĻā§ āύāϤā§āύ āĻā§āϞāĻžāϏ(New class) āϤā§āϰāĻŋ āĻāϰāĻž āĻšāϝāĻŧāĨ¤ āϤā§āϰāĻŋ āĻšāĻāϝāĻŧāĻž āύāϤā§āύ āĻā§āϞāĻžāϏāĻā§ “āĻĄāĻŋāϰāĻžāĻāĻāĻĄ āĻā§āϞāĻžāϏ(Derived Class)” āĻŦāĻž “āĻāĻžāĻāϞā§āĻĄ āĻā§āϞāĻžāϏ(Child class)” āĻŦāĻž “āϏāĻžāĻŦ āĻā§āϞāĻžāϏ(sub class)” āĻŦāϞāĻž āĻšāϝāĻŧ āĻāĻŦāĻ āĻŦāĻŋāĻĻā§āϝāĻŽāĻžāύ āĻā§āϞāĻžāϏāĻā§ “āĻŦā§āϏ āĻā§āϞāĻžāϏ(Base Class)” āĻŦāĻž “āĻĒā§āϝāĻžāϰā§āύā§āĻ āĻā§āϞāĻžāϏ(Parent Class)” āĻŦāĻž āϏā§āĻĒāĻžāϰ āĻā§āϞāĻžāϏ (Super Class) āĻŦāϞāĻž āĻšāϝāĻŧāĨ¤ [Inheritance is the ability to transfer properties from one class to another. Inheritance is one of the important features of object-oriented programming. Inheritance is a feature or process in which new classes are created from existing classes. The new class created is called “Derived Class” or “Child Class” or “Sub Class” and the existing class is called “Base Class” or “Parent Class” or “Super Class.”]
Polymorphism
“āĻĒāϞāĻŋāĻŽāϰāĻĢāĻŋāĻāĻŽ(Polymorphism)” āĻļāĻŦā§āĻĻāĻāĻŋ āĻšāϞ “āĻĒāϞāĻŋ” + “āĻŽāϰāĻĢāϏ”-āĻāϰ āϏāĻāĻŽāĻŋāĻļā§āϰāĻŖ, āϝāĻžāϰ āĻ āϰā§āĻĨ āĻ āύā§āĻ āϰā§āĻĒāĨ¤ āĻāĻāĻŋ āĻāĻāĻāĻŋ āĻā§āϰāĻŋāĻ āĻļāĻŦā§āĻĻāĨ¤ āĻ āĻŦāĻā§āĻā§āĻ-āĻāϰāĻŋāϝāĻŧā§āύā§āĻā§āĻĄ āĻĒā§āϰā§āĻā§āϰāĻžāĻŽāĻŋāĻ-āĻ āĻāĻŽāϰāĻž āϤāĻŋāύāĻāĻŋ āĻĒā§āϰāϧāĻžāύ āϧāĻžāϰāĻŖāĻž āĻŦā§āϝāĻŦāĻšāĻžāϰ āĻāϰāĻŋāĻ āĻāύāĻšā§āϰāĻŋāĻā§āϝāĻžāύā§āϏ, āĻāύāĻā§āϝāĻžāĻĒāϏā§āϞā§āĻļāύ āĻāĻŦāĻ āĻĒāϞāĻŋāĻŽāϰāĻĢāĻŋāĻāĻŽāĨ¤
Example: āĻāĻāĻžāύ⧠āϝā§āĻ(add) āĻĒā§āϰāĻā§āϰāĻŋā§āĻžāϰ āĻāĻĨāĻž āĻāĻŋāύā§āϤāĻž āĻāϰāϤ⧠āĻĒāĻžāϰāĻŋāĨ¤ āϝā§āĻŽāύ āĻĻā§āĻāĻŋ āĻ āĻĒāĻžāϰā§āύā§āĻĄ āϝāĻĻāĻŋ āϏāĻāĻā§āϝāĻž āĻšā§ āĻāĻŦāĻ āϏā§āĻā§āώā§āϤā§āϰ⧠āϝā§āĻ āĻĒā§āϰāĻā§āϰāĻŋā§āĻžāϰ āĻĢāϞ āĻšāĻŦā§ āĻāĻāĻāĻŋ āϏāĻāĻā§āϝāĻž āĨ¤ āĻāĻŦāĻžāϰ āĻĻā§āĻāĻŋ āĻ āĻĒāĻžāϰā§āύā§āĻĄ āϝāĻĻāĻŋ āϏā§āĻā§āϰāĻŋāĻ āĻšā§ āϏā§āĻā§āώā§āϤā§āϰ⧠āĻĻā§āĻāĻŋ āϏā§āĻā§āϰāĻŋāĻ āĻāϰ āϝā§āĻāĻā§ concatenate āĻŦāϞāĻž āĻšā§ā§ āĻĨāĻžāĻā§ āĻāĻŦāĻ āĻĢāϞāĻžāĻĢāϞ āĻšāĻŋāϏāĻžāĻŦā§ āĻāĻāĻāĻŋ āϏā§āĻā§āϰāĻŋāĻ āĻĒā§ā§ā§ āĻĨāĻžāĻāĻŋāĨ¤ i) 4+5=9 ii) poly+morphism=polymorphism āĻāĻā§āώā§āϤā§āϰ⧠āĻĻā§āĻāĻž āϝāĻžāĻā§āĻā§ āĻāĻāĻ “+” operator āĻĻā§āĻāĻŋ āĻāĻŋāύā§āύ āĻĢāϞāĻžāĻĢāϞ āĻĒā§āϰāĻĻāϰā§āĻļāύ āĻāϰā§āĻā§ āĨ¤ [The word polymorphism is a combination of poli + morphos, which means many forms. It’s a Greek word. In object-oriented programming, we use three main concepts: inheritance, encapsulation, and polymorphism. Example: Let’s consider the process of adding. For example, if two operands are numbers, the result of the addition process is a number. Again, if two operands are strings, then the sum of the two strings is called a concatenate and the result is a string. i) 4+5 = 9 ii) poly + morphism = polymorphism In this case, the same “+” operator shows two different results.]
Learn C++ Programming
C++ Question and Answer [2015-2019]
2015
1) Do the Following Task using C++ language in OOP
a) Design a Class having Name Circle
b) Declare an integer data for taking value of radius of that circle and take that input through get input() function
c) Find out the area of circle using another member function
#include<iostream>
using namespace std;
class circle{
public :
int r;
float area;
void input(){
cout<<"Enter radious of circle:";
cin>>r;
}
void findArea(){
area=3.14*r*r;
}
void display(){
cout<<"Area of circle is:";
cout<<area;
}
};
int main(){
circle obj;
obj.input();
obj.findArea();
obj.display();
}
2016
a) Write a program in C++ that accepts two number as input and find the sum using class and object
#include<iostream>
using namespace std;
class Sum_Two_Num{
public :
int a,b,sum;
void inputNumber(){
cout<<"Enter Two Number :";
cin>>a>>b;
}
void findSum() {
sum=a+b;
}
void display() {
cout<<"Sum of two number is:";
cout<<sum;
}
};
int main(){
Sum_Two_Num obj;
obj.inputNumber();
obj.findSum();
obj.display();
}
b) What is Polymorphism? Explain with example
“āĻĒāϞāĻŋāĻŽāϰāĻĢāĻŋāĻāĻŽ(Polymorphism)” āĻļāĻŦā§āĻĻāĻāĻŋ āĻšāϞ “āĻĒāϞāĻŋ” + “āĻŽāϰāĻĢāϏ”-āĻāϰ āϏāĻāĻŽāĻŋāĻļā§āϰāĻŖ, āϝāĻžāϰ āĻ āϰā§āĻĨ āĻ āύā§āĻ āϰā§āĻĒāĨ¤ āĻāĻāĻŋ āĻāĻāĻāĻŋ āĻā§āϰāĻŋāĻ āĻļāĻŦā§āĻĻāĨ¤ āĻ āĻŦāĻā§āĻā§āĻ-āĻāϰāĻŋāϝāĻŧā§āύā§āĻā§āĻĄ āĻĒā§āϰā§āĻā§āϰāĻžāĻŽāĻŋāĻ-āĻ āĻāĻŽāϰāĻž āϤāĻŋāύāĻāĻŋ āĻĒā§āϰāϧāĻžāύ āϧāĻžāϰāĻŖāĻž āĻŦā§āϝāĻŦāĻšāĻžāϰ āĻāϰāĻŋāĻ āĻāύāĻšā§āϰāĻŋāĻā§āϝāĻžāύā§āϏ, āĻāύāĻā§āϝāĻžāĻĒāϏā§āϞā§āĻļāύ āĻāĻŦāĻ āĻĒāϞāĻŋāĻŽāϰāĻĢāĻŋāĻāĻŽāĨ¤
Example :
class MotorBike {
public:
void speed() {
cout << "This is Hero's speed \n" ;
}
};
// Derived class
class Honda : public MotorBike {
public:
void speed() {
cout << "This is Honda's speed \n" ;
}
};
// Derived class
class Enfield : public MotorBike {
public:
void speed() {
cout << "This is Enfield's speed\n" ;
}
};
2017
a) Write a program in C++ to check an integer whether it is odd or even using class and object?
// Answer:
#include<iostream>
using namespace std;
class Odd_Even {
int num;
public:
void input() {
cout << "Enter a number:";
cin>>num;
}
void Check_OddEven() {
if (num % 2 == 0) {
cout << "Number is even:" << num;
} else {
cout << "Number is odd:" << num;
}
}
};
int main() {
Odd_Even obj;
obj.input();
obj.Check_OddEven();
return 0;
}
b) What do you mean by Data Member? Give example?
Data Members are variable which are declared in any class by using any fundamental data types (like int, char, float etc) or derived data type (like class, structure, pointer etc.).
There are two types of data member 1) Private 2) Public
//Example :
class DataMember {
private:
int x;
float a;
public:
int m;
float n;
};
OR
a) Give the difference between public and private member of the class in C++
| Public | Private |
| 1. All the class members and functions are available to everyone. | 1.The class members can be accessed only by the functions inside the class. |
| 2. The public member can be accessed from anywhere in the program using the dot operator(.)with the object of that class. | 2.the member functions or the friend functions are allowed to access the private data members of a class |
| Example: class Subtraction { public: int a,b; int calculate(){ return (a-b); } }; int main(){ Substraction obj; // accessing public data member outside class obj.a=20; obj.b=10; cout<<“Substraction is: ” << obj.calculate(); return 0; } | Example: class Subtraction { private: int a,b; private: void calculate(int x,int y){ a=x; b=x; int result=a-b; cout<<“Substraction is=”<<result; } }; int main(){ Substration obj; obj.calculate(20,10); return 0; } |
b) Describe the characteristic of destructor in C++
- The destructor has the same name as that of the class prefixed by the tilde character â~â.
- The destructor cannot have parameters.
- It has no return type
- there can be only one destructor in a class
- The destructor is executed automatically when the control reaches the end of the class scope to destroy the object
c) What do you mean by “get from” Operator in C++? Give example?
Ans: Extraction Operator (>>) sometimes known as “get from” operator which is usually used for input data from the user
2018
a) Write a program in C++ using class and object to check an integer whether is a prime number or not.
#include <iostream>
using namespace std;
class PrimeChecker {
private:
int num; //here i have used private
public:
// Constructor
PrimeChecker(int n) {
num = n;
}
// Function to check if the number is prime
int isPrime() {
if (num <= 1) {
cout << "The number is not prime." << endl;
return 0;
}
for (int i = 2; i <= num / 2; ++i) {
if (num % i == 0) {
cout << "The number is not prime." << endl;
return 0;
}
}
cout << "The number is prime." << endl;
return 1;
}
};
int main() {
int number;
cout << "Enter an integer number: ";
cin >> number;
// Create an object of PrimeChecker class
PrimeChecker primeObj(number);
// Call the isPrime function
primeObj.isPrime();
return 0;
}
b) What is the member function? Give example?
A member function of a class is a function that has its definition or its prototype within or outside the class. member function knows as a method also.
There are two way to define a function
1) inside the class-defined directly
2) outside of the class- using scope resolution operator(::) along with class name
// Example:
// Member functions defined within class
class Circle {
public:
double r=2.5; // variable
double getArea(void) {
return 3.14*r*r;
}};
//OR Member functions defined outside of the class
class Circle {
public:
double r=2.5; // variable
};
class Circle::double getArea(void) {
return 3.14*r*r;
}
int main(){
Circle obj;
cout<<"Area of Circle:"<<obj.double getArea();
}
OR
a) Write a program in C++ to find out the factorial of a given integer (N!= 1x2x3x……..N)
Answer:
using namespace std;
class FindFactorial {
public:
int factorial(int N) {
int i, f = 1;
for (i = 1; i <= N; i++) {
f = f*i;
}
return f;
}
};
int main() {
FindFactorial obj;
int N;
cout << "Enter a number:";
cin >> N;
cout << "Factorial is:" << obj.factorial(N);
return 0;
}
b) How a member function can be declared outside of the class? Give example?
Anwser:
A member function can be declared outside of the class using the scope resolution operator (::) along with the class name(āĻāĻāĻāĻŋ āĻŽā§āĻŽā§āĻŦāĻžāϰ āĻĢāĻžāĻāĻļāύāĻā§ āĻā§āϞāĻžāϏā§āϰ āĻŦāĻžāĻāϰ⧠āϏā§āĻā§āĻĒ āϰā§āĻāϞā§āϝā§āĻļāύ āĻ āĻĒāĻžāϰā§āĻāϰ (::) āĻāϰ āϏāĻžāĻšāĻžāϝā§āϝ⧠āĻā§āϞāĻžāϏā§āϰ āύāĻžāĻŽā§āϰ āϏāĻžāĻĨā§ āĻĄāĻŋāĻā§āϞā§āϝāĻŧāĻžāϰ āĻāϰāĻž āϝā§āϤ⧠āĻĒāĻžāϰā§). Example:
class Circle {
public:
double r=2.5; // variable
};
class Circle::double getArea(void) {
return 3.14*r*r;
}
int main(){
Circle obj;
cout<<"Area of Circle:"<<obj.double getArea();
}
2019
a) Write a program in C++ using class and object to find out the sum 1 to N where N is an integer given as input.
Answer:
#include<iostream>
using namespace std;
class Sum_Of_N_Num{
public :
int N,i,sum=0;
void inputNumber(){
cout<<"Enter Number :";
cin>>N;
}
void findSum()
{
for(i=0; i<=N; i++){
sum=sum+i;
}
}
void display()
{
cout<<"Sum of N number is:";
cout<<sum;
}
};
int main(){
Sum_Of_N_Num obj;
obj.inputNumber();
obj.findSum();
obj.display();
}
b)Write a function of setw and endl manipulator.
Answer:
endl : This manipulator has the same functionality as â\nâ(newline character). But this also flushes the output stream(āĻāĻ āĻŽā§āϝāĻžāύāĻŋāĻĒā§āϞā§āĻāϰā§āϰ āĻāĻžāϰā§āϝāĻāĻžāϰāĻŋāϤāĻž ‘\n’-āĻāϰ (New line character) āĻŽāϤā§āĻāĨ¤ āĻāĻŋāύā§āϤ⧠āĻāĻāĻŋ āĻāĻāĻāĻĒā§āĻ āϏā§āĻā§āϰāĻŋāĻŽāĻ āĻĢā§āϞāĻžāĻļ āĻāϰā§āĨ¤).
setw(): This manipulator declare in imanip.h . it changes the width of the output field. When used in an expression out << setw(n)output field. (āĻāĻ āĻŽā§āϝāĻžāύāĻŋāĻĒā§āϞā§āĻāϰāĻāĻŋ imanip.h-āϤ⧠āĻĄāĻŋāĻā§āϞā§āϝāĻŧāĻžāϰ āĻāϰāĻž āĻšāϝāĻŧā§āĻā§āĨ¤ āĻāĻāĻŋ āĻāĻāĻāĻĒā§āĻ āĻĢāĻŋāϞā§āĻĄā§āϰ āĻĒā§āϰāϏā§āĻĨ āĻĒāϰāĻŋāĻŦāϰā§āϤāύ āĻāϰā§āĨ¤ āϝāĻāύ out << setw(n) āĻāĻ āĻ āĻāĻŋāĻŦā§āϝāĻā§āϤāĻŋāϤ⧠āĻŦā§āϝāĻŦāĻšā§āϤ āĻšāϝāĻŧ, āĻāĻāĻāĻĒā§āĻ āĻĢāĻŋāϞā§āĻĄā§āϰ āĻĒā§āϰāϏā§āĻĨ n āĻšāϝāĻŧā§ āϝāĻžāϝāĻŧāĨ¤”)
Example:
#include<iostream>
#include<iomanip>
using namespace std;
int main(){
cout<<"USING setw() ..............\n";
cout<< setw(10) <<11<<endl;
cout<< setw(10) <<2222<<endl;
cout<< setw(10) <<33333<<endl;
cout<< setw(10) <<4<<endl;
}
OR
a) Write a program in C++ to print the reverse of given number.
Answer:
#include <iostream>
using namespace std;
int main() {
int num, revNum = 0, rem;
cout << "Enter an integer: ";
cin >> num;
while(num!= 0) {
rem = num%10;
num /= 10;
revNum = revNum*10 + rem;
}
cout << "Reversed Number = " << revNum;
return 0;
}
b) what do you mean by reference variable? Give example?
Answer: When a variable is declared as a reference, it becomes an alternative name for an existing variable. A variable can be declared as a reference by putting ‘&’ in the declaration.(āϝāĻāύ āĻāĻāĻāĻŋ āĻā§āϰāĻŋāϝāĻŧā§āĻŦāϞāĻā§ āϰā§āĻĢāĻžāϰā§āύā§āϏ āĻšāĻŋāϏā§āĻŦā§ āĻĄāĻŋāĻā§āϞā§āϝāĻŧāĻžāϰ āĻāϰāĻž āĻšāϝāĻŧ, āϏā§āĻāĻŋ āĻā§āύ⧠āĻŦāĻŋāĻĻā§āϝāĻŽāĻžāύ āĻā§āϰāĻŋāϝāĻŧā§āĻŦāϞā§āϰ āĻāύā§āϝ āĻāĻāĻāĻŋ āĻŦāĻŋāĻāϞā§āĻĒ āύāĻžāĻŽ āĻšāϝāĻŧā§ āĻĻāĻžāĻāĻĄāĻŧāĻžāϝāĻŧāĨ¤ āĻĄāĻŋāĻā§āϞā§āϝāĻŧāĻžāϰā§āĻļāύ⧠‘&’ āϏāĻžāĻāύ āĻŦā§āϝāĻŦāĻšāĻžāϰ āĻāϰ⧠āĻāĻāĻāĻŋ āĻā§āϰāĻŋāϝāĻŧā§āĻŦāϞāĻā§ āϰā§āĻĢāĻžāϰā§āύā§āϏ āĻšāĻŋāϏā§āĻŦā§ āĻĄāĻŋāĻā§āϞā§āϝāĻŧāĻžāϰ āĻāϰāĻž āϝā§āϤ⧠āĻĒāĻžāϰā§āĨ¤)
Example:
#include<iostream>
using namespace std;
int main(){
int x=10;
int& ref=x;
//value of x is now changed
ref=20;
cout<<"x="<<x<<endl;
//value of ref is now changed
x=30;
cout<<"ref="<<ref<<endl;
return 0;
}


