JAVA SE
(CORE JAVA)
LECTURE-13
Today’s Agenda
• Object Oriented Programming.
• Classes and Objects.
• Pillars of Object Oriented Programming
• Creating a class and its object.
Object Oriented
Programming
A programming paradigm which is based on real
world model of objects or entities.
It is organized around objects rather than "actions"
and data rather than “logic”.
Object-oriented programming takes the view that
what we really care about are the objects we want to
manipulate rather than the logic required to
manipulate them.
Objects
• In programming any real world entity which has specific
attributes or features can be represented as an Object.
• Along with attributes each object can take some
actions also which are called it’s “behaviors”
• In programming world, these attributes are called data
members and behaviours/actions are called “functions”
or “methods”
Are you an object ?
• Yes , we humans are objects because:
• We have attributes as name, height, age etc.
• We also can show behaviors like walking, talking, running,
eating etc
Classes
• Now to create/represent objects we first have to write all their
attributes under a single group .
• This group is called a class
• A class is used to specify the basic structure of an object and it
combines attributes and methods to be used by an object
• Thus we can say that a class represents the data type and object
represents a kind of variable of that data type
• For Example:- Each person collectively come under a class
Objects and Classes
Objects and Classes
Objects and Classes
Objects and Classes
Pillars of OOP
• The Object Oriented Programming paradigm stands on 3
main pillars, which are :-
1. Abstraction and Encapsulation
2. Polymorphism
3. Inheritance
Abstraction and Encapsulation
Abstraction : Focus on the meaning i.e. Suppress
irrelevant “implementation” details.
Encapsulation is a process of binding or wrapping the data
and the codes that operates on the data into a single
entity.
Abstraction and Encapsulation go hand in hand.
Polymorphism
Poly- Many
Morph- Forms
Polymorphism refers to a principle in biology in which
an organism or species can have many different forms
or stages.
Have you seen how you perform polymorphism in day
to day life?
Example
Inheritance
A process by which one class can acquire properties
of another class.
Example:- We inherit characteristics from our
parents.
Advantages of inheritance
Reusability
Extensibility
Information is made manageable in a hierarchical
order.
Creating a class
and its object
• Syntax :-
class <class name>
Optional
{
<access modifier> <data type> <variable name>= value;
-
-
-
<access modifier> <return type> <method name>(arguments)
{
// Method body
}
}
• Example :-
1000
class Student 0 roll
{
1000 ‘\n’ grade
int roll;
s
char grade; 0.0 per
float per;
}
class UseStudent
{
public static void main(String [ ] args)
{
Student s;
s=new Student();
}
Continued Program
class UseStduent
{
public static void main(String [ ] args)
{
Student s;
s=new Student( );
Does this code violate the
s.roll=10;
rules of Object Oriented
s.grade=‘A’; Programming ???
s.per=66.5f;
It violates the rule of
S.O.P(“Roll is ”+s.roll); Encapsulation.
S.O.P(“Grade is ”+s.grade);
S.O.P(“Percentage is ”+s.per);
}
Access Modifiers
• There are 4 access modifiers provided by java which are,
• public
• private
• protected
• default
• public and private are of importance to us unless we learn
“Packages” in Java.
End Of Lecture 13
For any queries mail us @: scalive4u@gmail.com
Call us @ : 0755-4271659, 7879165533
Agenda for Next Lecture:
1. Creating methods in a class.
2. Using methods to initialize data members.
3. Creating parameterized methods.