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;
}

Leave a Comment

Index