Professional Documents
Culture Documents
ORIENTED PROGRAMMING
Learning Objectives
" Types of Computer Languages " Programming Paradigms
. Principles of Object-Oriented Programming
Communication is the medium through which we can express our ideas to others. To communicate with
other people, we need a language like Hindi, English, Bengali, etc. Similarly, a programmer needs a language
to communicate with the computers. These are called computer languages. Computer language is an interface
between acomputer and human beings. It is a set of words, symbols and codes that the computer can understand.
Itis usedto write a computer program.
Fifth-generationlanguages (5GL)
Thefifth-generation languages, also known as natural languages are the programming languages that have visual
tools todevelop a program. Examples of fifth generation language include Mercury, OPSS, and Prolog. Natural
to use.
language is very easy
Natural languages are often associated with expert system and artificial intelligence. These systems are popular
inthe medical and scientific fields, but are not widely used in business applications.
For example, if a program is written in 4GL to get the names of students whose marks exceed 95, it might be
written as:
ertBCT LAST-NAME, FIRST-NAME FROM STUDENT WHERE MARKS > 95.
Anatural language version ot the same program might be written as:
TELL ME THE NAME OF STUDENTS WITH MARKS OVER 95.
Advantages of High-Level Languages
High-level language is user friendly.
High-level language is similar to English language, therefore it is easier to use.
High-level language requires less time to code.
High-level language is easier to maintain.
High-level language is problem oriented.
Programs written ina high-level language can be translated into machine language and therefore can run on
any computer with an appropriate translator.
It is independent of the machine on which it is used, i.e., programs developed in high-level languages can be
executed on any computer i.e.,they are machine independent.
Disadvantages of High-Level Languages
Ahigh-level language has to be translated into the machine language by a translator and thus it wastes a lot of
the computer time.
The object code generated by a translator might be inefficient as compared to an equivalent assembly language
program.
Encapsulation
Encapsulation is one of the basic concepts of
The wrapping up of data members and memberobject-oriented programming (0OP).
methods together into a single unit Methods Variables
is caled encapsulation.)lt means that data can be
accessed in the associated function CLASS
only and safe from outside interference and misuse thus leading to
the important Concept of Encapsulation
concept of 0OP known as data hiding.
Areal-life example is a capsule. In general, a capsule is a
small case or
shape which protects the drug inside it from getting contaminated withcontainer, especially round or cylindrical in
the dust particles from outside.
Similarly, Methods and Variables are enclosed within a unit called class.
Example of Encapsulation using class:
Both Data Members and Member Methods are
enclosed within the braces of the class country.
class country
Class name
String name;
String capital; Data Members
void input 0
void di splay )
INHERITANCE
Father Son
All the properties of father are inherited by his son.
VEHICLE
Polymorphism
The word Polymorphism comes from the Greek word mearning "many forms" ("poly" means many and "morphe'
means form). It is the ability which allows some variables to exhibits one or more forms.
For example, CAR sometimes is used as a family car, a car used by general public such as Taxi and also used as
Pool Car used by students of aschool.
(In object-oriented programming, polymorphism
is the feature of being able to allot a dissimilar
PRIVATE CAR
meaning so that a variable, a method, or an object
can have more than one form)Thus it is the capability
of altering the characteristícs and behaviour of
a variable and use it in many forms according to
the need of an object. It allows multiple objects CAR PUBLIC CAR
Let's Revisit
.(Computer Languages can be claified in three different languages. They are Machine level Language, Assermbly
Level Language and High-Level Language.
(Procedure-oriented programming and Object-oriented prograrnming are two approaches of High-Level
languages. )
The programming language that breaks down a programming assignment into a group of variables, data
structures and sub programs is called Procedural oriented programming languages.
A
programming model that depends on the theory of classes and objects, and gives importance on data rather
than functions is known as Object-oriented programming.
(FORTRAN, COBOL, BASIC are some of the POP languages and Java, C++,C#, Python are some commonly
known OOP languages.)
Principles of 0OP's are Data Abstraction, Inheritance, Polymorphism and Encapsulation.
vThe wrapping up of data members and Member methods together into a single unit is called Encapsulation.
vbata Abstraction is the property by which the essential features are shown without knowing the background
details.
inheritance is the method which allows one class to inherit the properties (data members and member methods)
of another class.
WPolymorphism is the feature of being able to allot adissimilar meaning so that a variable, a method or an object
can have more than one form.
MIND DRILL
Solved Questions
A. Tick () the correct answer.
1. Aprogrammer needs a computer language to communicate with a
a. Another programmer b Computer
c. Animal d Anon-living thing
2. Which of the following is auser friendly computer language?
Machine Level language b Assembly Level Language
C High LevelLanguage d None of these
Answers
5. Encapsulation
1. methods or procedures 2. many forms 3. characteristics 4.Object-oriented program
10. Derived
6. Re-usability 7.Language translator 8. Bottom-Up 9. instances
Super class is known as Base class. Sub class is also known as Derived clasS.w