Chapter 1 Unit 1
Chapter 1 Unit 1
Machine Language:
In this language instructions are written in the form of binary i.e. 0 or 1. Instructions written in
this language is called machine code or object code. This language is the internal language of
machine. Therefore, no translation is required. Program execution is faster. It is a machine
dependent language. But disadvantage is writing program is difficult, finding errors and
correction is difficult.
Assembly Language:
In this language instructions are written in the form of mnemonics/symbolic code. It is little bit
easier to write the program as compared to machine language. It is also machine dependent
language. In this language a translator program is used to translate assembly language into
machine language called Assembler. Program execution is slower than machine language.
Compiler Interpreter
It translates whole source code into It translates source code into object code
object code at once. line by line.
It displays all the errors of the program It displays one error at a time. After
together. correction of the error it displays next.
Compilation process is faster Interpretation process is slower.
Elements of OOP
1. Object: It is an identifiable entity which has some characteristics and behavior. It is called
instance of the class. It is created by using new keyword. Many objects can be created from
a class. Example:- FAN – Characteristics are no. of wings, color, brand etc. and behavior is
rotate.
2. Class: It is a blueprint or prototype for the object. It defines common characteristics and
behavior for the object. It is called as object factory because from a class many similar kinds
of objects can be created. It is created only once and created by using class keyword.
Difference between class and object
Class Object
1. It is a blueprint or prototype for the 1. It is an identifiable entity which
objects which defines the common have some characteristics and
characteristics and behavior for the objects behavior
2. It is called as object factory 2. It is called as instance of the class
3. It is created once 3. Many objects can be created
4. It is created by using class keyword 4. It is created by using new
keyword
Principles of OOP
1. Data Abstraction
It is an act of presenting essential features without including background details.
In abstraction the implementation details are not considered by the user.
Ex - Switch board
In switch board, only the switches are presented but how the current is flowing from switch to
device that is hidden
2. Inheritance
It is a principle in which the object of one class acquires the properties of another class. The
class which is inherited to another class is known as super class or parent class. The class which
inherits from super class is known as sub class or derived class.
The inheritance is done by using extends keyword
Advantages
1. It provides the reusability feature
2. Easy extension of existing code
3. Improves the programmer's productivity
Example:
3. Polymorphism
It is a principle in which more than one function having same name but behaves differently
with different set of values. It is also known as function overloading.
Example 1:
Example 2:
+ operator
5+3 = 8 (Addition when + operator is working with numbers)
"5"+"3" = 53 ( Concatenation when + operator is working with string values)
4. Encapsulation
The wrapping up of data and functions into a single unit called class is known as encapsulation.
In encapsulation implementation details are hidden from the user
Example 1 -
Medicine capsule in which different medicines are encapsulated in a single capsule
Example 2 -
Cola vending machine in which cola cans and the mechanism are encapsulated into a single
unit i.e. cola vending machine.
What is reusability?
It means the properties of one class can be reused in another class. It is an important feature
of inheritance.
What is compilation?
It is a process of converting source code into object code.