Professional Documents
Culture Documents
What is OOP?
Object-Oriented Programming is a methodology or
paradigm to design a program using classes and
objects.The following are some concepts involving
OOPs.
Class
Object
Inheritence
Polymorphism
Abstraction
Encapsulation
Object
Any entity that has state and behavior
is known as an object. For example a
chair, pen, table, keyboard, bike, etc.
It can be physical or logical.
It is defined as an instance of a class.
e.g. : A dog is an object because it
has states like color, name, breed,
etc.
Class
Collection of objects is called class. It is a
logical entity.
A class can also be defined as a blueprint
from which you can create an individual
object. Class doesn't consume any space.
Access Modifiers In JAVA
package p2;
package p1;
import p1.*;
//Class Geeks is having Default access modifier //This class is having default access modifier
class Geek class GeekNew
{ {
}
obj.display();
}
}
2.Private
Private: The private access modifier is specified using the keyword private.
The methods or data members declared as private are accessible only within the
class in which they are declared.
Any other class of same package will not be able to access these members.
It is illustrated in the following example:
Private(cont)
class A {
}
3.Protected
Private: The protected access modifier is specified using the keyword protected.
It is similar to private members but the only difference is that the protected
members are accessible within all classes of the same package whereas private
members are not.
It is illustrated in the following example:
4.Public
Private: The protected access modifier is specified using the keyword protected.
The member which has been declared public is visible to the world.
Access Modifiers In JAVA(cont)
Inheritance
Inheritance is a mechanism wherein a new
class is derived from an existing class.
A class that is derived from another class is
called subclass or derived class.
A class from which other classes are
derived is known as Base class.
The real life example of inheritance is child
and parents, all the properties of father are
inherited by his son.
Inheritance: Car ← Vehicle
Inheritance: Bike ← Vehicle
Inheritance:Main Class
Output
Polymorphism
If one task is performed by different ways,
it is known as polymorphism.
Suppose if you are in class room that time
you behave like a student, when you are
in market at that time you behave like a
customer, when you at your home at that
time you behave like a son or daughter,
Here one person present in different-
different behaviors.
Abstraction
Abstraction is the process of abstraction in
Java which is used to hide certain details
and only show the essential features of
the object. In other words, it deals with the
outside view of an object (interface).
when we ride a bike, we only know
about how to ride bikes but can not
know about how it work? And also we
do not know the internal functionality
of a bike.
Advantages of
Abstraction