0% found this document useful (0 votes)
14 views13 pages

1.1 Study Materials Object Oriented Programming Abstraction, Objects, Classes, Encapsulation, Inheritance, Polymorphism

The document provides an overview of Object-Oriented Programming (OOP) concepts, including definitions and examples of objects, classes, encapsulation, abstraction, inheritance, and polymorphism. It explains how these concepts are implemented in Java, highlighting the relationships between classes and objects, and the importance of encapsulation for data security. Additionally, it discusses real-life examples to illustrate these OOP principles.

Uploaded by

Infinite Elixir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views13 pages

1.1 Study Materials Object Oriented Programming Abstraction, Objects, Classes, Encapsulation, Inheritance, Polymorphism

The document provides an overview of Object-Oriented Programming (OOP) concepts, including definitions and examples of objects, classes, encapsulation, abstraction, inheritance, and polymorphism. It explains how these concepts are implemented in Java, highlighting the relationships between classes and objects, and the importance of encapsulation for data security. Additionally, it discusses real-life examples to illustrate these OOP principles.

Uploaded by

Infinite Elixir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

II III

20CSPC301
OBJECT ORIENTED PROGRAMMING
(Common to CSE, IT, CSBS)

UNIT No. I

INTRODUCTION TO OOP AND JAVA


FUNDAMENTALS
1.1 Object Oriented Programming ,
Abstraction, Objects &
Classes ,Encapsulation, Inheritance,
Version: 1.XX

UNIT No.
1
OOP INTRODUCTION
20CSPC301
OBJECT ORIENTED PROGRAMMING (Common to CSE, IT, CSBS)

Object-Oriented Programming is a methodology or paradigm to design a


program using classes and objects.
⮚ The Basic concepts of OOP are:

Object

⮚ Object means a real word entity or physical as well as logical entity such
as pen, chair, table etc.
⮚ Any entity that has state and behavior is known as an object.

⮚ Object can be defined as an instance of a class.


⮚ Car, bike, truck these all belong to vehicle class. These Objects also have
different states and behaviors. For Example cars have state - color, name, model,
speed, Mileage. as we say behaviors - distance travelled.
20CSPC301
OBJECT ORIENTED PROGRAMMING (Common to CSE, IT, CSBS)

Class

⮚ A class can also be defined as a blueprint which contains only a list of


variables and methods and no memory is allocated for them.
⮚ It is a logical entity.

⮚ A class is a group of objects that has common properties.


Encapsulation

⮚ Encapsulation is a process of wrapping of data and methods in a single


unit is called encapsulation. Encapsulation is achieved in C++/Java language by class
concept.
⮚ The main advantage of encapsulation is to secure the data from other
methods, when we make a data private then this data is only used within the class,
but these data not accessible outside the class.
Abstraction

⮚ Abstraction is a process of hiding the implementation details and showing


only functionality to the user. For example: phone call, we don't know the internal
processing- Data Abstraction
⮚ It is the concept of exposing only the required essential characteristics and
behaviour with respect to a context.
⮚ In object oriented programming language this is implemented
automatically while writing the code in the form of class and object.

⮚ Car, bike, truck these all belong to vehicle class. These Objects also have
different states and behaviors. For Example cars have state - color, name, model,
speed, Mileage. as we say behaviors - distance travelled.
20CSPC301
OBJECT ORIENTED PROGRAMMING (Common to CSE, IT, CSBS)

Inheritance
Inheritance can be defined as the procedure or mechanism of acquiring all
the properties and behavior of one class to another, i.e., acquiring the properties and
behavior of a child class from the parent class.
Polymorphism

⮚ Polymorphism means ‘Many forms’

⮚ If ‘one task is performed in different ways’ known as Polymorphism

Let's discuss above each OOPS concept with a real-world example.


Object
⮚ The Object is the real-time entity having some state and behavior.

⮚ In Java, Object is an instance of the class having the instance variables


like the state of the object and the methods as the behavior of the object

⮚ The object of a class can be created by using the new keyword in Java
Programming language.

Various Object Definitions:

1. An object is a real-world entity.

2. An object is a runtime entity.

3. The object is an entity which has state and behavior.

⮚ Car, bike, truck these all belong to vehicle class. These Objects also have
different states and behaviors. For Example cars have state - color, name, model,
speed, Mileage. as we say behaviors - distance travelled.
20CSPC301
OBJECT ORIENTED PROGRAMMING (Common to CSE, IT, CSBS)

4. The object is an instance of a class.

An Object has three characteristics:

⮚ State
⮚ Behavior
⮚ Identity

State: Represents data (value) of an object.

Behavior: Represents the behavior (functionality) of an object such as


deposit, withdraw etc.
Identity: Object identity is typically implemented via a unique ID. The value of
the ID is not visible to the external user. But, it is used internally by the JVM to identify
each object uniquely.

Class

⮚ A class is a template or blueprint from which objects are created. So, an


object is the instance (result) of a class.
⮚ A class is a group of objects which have common properties. It is a
template or blueprint from which objects are created.
⮚ In short, a class is the specification or template of an object.

A class contains:
⮚ Car, bike, truck these all belong to vehicle class. These Objects also have
different states and behaviors. For Example cars have state - color, name, model,
speed, Mileage. as we say behaviors - distance travelled.
20CSPC301
OBJECT ORIENTED PROGRAMMING (Common to CSE, IT, CSBS)

⮚ Data Member

⮚ Method

⮚ Constructor

⮚ Block
⮚ Class and Interface

Real life example of object and class

Vehicle class

⮚ Car, bike, truck these all belong to vehicle class. These Objects also have
different states and behaviors. For Example cars have state - color, name, model,
speed, Mileage. as we say behaviors - distance travelled.
20CSPC301
OBJECT ORIENTED PROGRAMMING (Common to CSE, IT, CSBS)

Difference between Class and Object in Java

S.No Class Object

Class is a container
1 which collection of object is an instance of class

variables and methods.

Sufficient memory space will


No memory is allocated
be allocated for all the
2 at the time of declaration
variables of class at the time of
declaration.

⮚ Car, bike, truck these all belong to vehicle class. These Objects also have
different states and behaviors. For Example cars have state - color, name, model,
speed, Mileage. as we say behaviors - distance travelled.
20CSPC301
OBJECT ORIENTED PROGRAMMING (Common to CSE, IT, CSBS)

One class definition For one class multiple


3
should exist only once objects can be created.
in the program.

Syntax to declare a Class:

class Class_Name

{
data member 1;

data member 2;

data member N; method 1;

method 2;

method N;

Simple Example of Object and Class

Class Employee

{
int eid; // data member (or instance variable) String ename; // data
⮚ Car, bike, truck these all belong to vehicle class. These Objects also have
different states and behaviors. For Example cars have state - color, name, model,
speed, Mileage. as we say behaviors - distance travelled.
20CSPC301
OBJECT ORIENTED PROGRAMMING (Common to CSE, IT, CSBS)

member (or instance variable) eid=101;

ename="Hitesh";

public static void main(String args[])

Employee e=newEmployee(); // Creating an object of class Employee

System.out.println("Employee ID: "+e.eid);

System.out.println("Name: "+e.ename);

}
}

Output:

Employee ID: 101

Name: Hitesh

Abstraction
⮚ Abstraction is the concept of exposing only the required essential characteristics
and behavior with respect to a context.
⮚ Hiding of data is known as data abstraction/Information Hiding. In object
oriented programming language this is implemented automatically while writing the code in
the form of class and object.

Real Life Example of Abstraction in Java


⮚ Car, bike, truck these all belong to vehicle class. These Objects also have
different states and behaviors. For Example cars have state - color, name, model,
speed, Mileage. as we say behaviors - distance travelled.
20CSPC301
OBJECT ORIENTED PROGRAMMING (Common to CSE, IT, CSBS)

Abstraction shows only important things to the user and hides the internal details, for
example, when we ride a bike, we only know about how to ride bikes, but did not know
about how it works?

Encapsulation
⮚ Encapsulation is a process of wrapping of data and methods in a single unit is called
encapsulation.
⮚ Encapsulation is achieved in java language by class concept.
⮚ Combining state and behavior in a single container is known as encapsulation. In java
language encapsulation can be achieved using class keyword, state represents
declaration of variables on attributes and behavior represents operations in terms of
method.

⮚ Car, bike, truck these all belong to vehicle class. These Objects also have
different states and behaviors. For Example cars have state - color, name, model,
speed, Mileage. as we say behaviors - distance travelled.
20CSPC301
OBJECT ORIENTED PROGRAMMING (Common to CSE, IT, CSBS)

Advantage of Encapsulation

⮚ The main advantage of using encapsulation is to secure the data from other methods,
when we make a data private then these data only use within the class, but these data
are not accessible outside the class.
Real life example of Encapsulation in Java
⮚ The common example of encapsulation is capsule. In capsule all medicine are
encapsulated inside capsule.

⮚ Car, bike, truck these all belong to vehicle class. These Objects also have
different states and behaviors. For Example cars have state - color, name, model,
speed, Mileage. as we say behaviors - distance travelled.
20CSPC301
OBJECT ORIENTED PROGRAMMING (Common to CSE, IT, CSBS)

Inheritance

⮚ The process of obtaining the data members and methods from one class to another
class is known as inheritance. It is one of the fundamental features of object-oriented
programming.
⮚ Types of inheritance in java: single, multilevel and hierarchical inheritance. Multiple
and hybrid inheritance is supported through interface only.

Important points

⮚ In the inheritance the class which is given data members and methods is known as

⮚ Car, bike, truck these all belong to vehicle class. These Objects also have
different states and behaviors. For Example cars have state - color, name, model,
speed, Mileage. as we say behaviors - distance travelled.
20CSPC301
OBJECT ORIENTED PROGRAMMING (Common to CSE, IT, CSBS)

base or super or parent class.


⮚ The class which is taking the data members and methods is known as sub or derived
or child class.
⮚ The data members and methods of a class are known as features.

⮚ The concept of inheritance is also known as re-usability or extendable classes or sub


classing or derivation.

⮚ Car, bike, truck these all belong to vehicle class. These Objects also have
different states and behaviors. For Example cars have state - color, name, model,
speed, Mileage. as we say behaviors - distance travelled.

You might also like