A program is organized in one of two ways:
- around its code (what is happening)
- around its data (who is being affected)
In structured programming techniques, programs are typically organized around code ("code acting on data").
Object-oriented programming took the ideas of structured programming and combined them with several new concepts. The principles of Object-Oriented Programming are discussed below:
1. Encapsulation
Encapsulation is the mechanism that binds code and data together. It keeps data safe from outside interference and misuse. The access to the code and data is managed by access specifiers.
Within an object, code, data, or both may be private to that object or public. Private code or data is accessible only within the object, they are not accessible by outside object. If code or data is public, other parts of the program may access it even though it is defined within an object.
Generally, the public parts of an object are used to provide a controlled interface to the private elements of the object.
2. Polymorphism
Polymorphism can be characterized by the phrase "one interface, multiple methods." Polymorphism allows one interface to control access to a general class of actions.
3. Inheritance
Inheritance is the process by which one object acquires the properties of another object(s). It supports hierarchical classification. Let us try our first program which will print
Hello World
and will test the environment.
Standard Input/Output
In the following program, we will show you, how to take input from a standard input device (i.e. keyboard) and how to print in a standard output device (i.e. monitor).
Note that,
cout
,
cin
and
cerr
are the objects of the standard output stream, standard input stream and standard error stream, respectively.
The
cout
object is used in conjunction with the stream insertion operator
(<<) to display the output on the console.
The
cin
object is used in conjunction with the stream insertion operator
(>>) to display the output on the console.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.