Untitled Document
Untitled Document
❖ Object
● An entity that has state and behavior is known as an object e.g.. chair, bike, marker,
pen, table, car, etc. It can be physical or logical (tangible and intangible). The
example of an intangible object is the banking system.
3. Identity: An object identity is typically implemented via a unique ID. The value of the
ID is not visible to the external user. However, it is used internally by the JVM to
identify each object uniquely.
For Example. Pen is an object. Its name is Reynolds; color is white, known as its state. It is
used to write, so writing is its behavior.
❖ Class
1. Fields
2. Methods
3. Constructors
4. Blocks
5. Nested class and interface
Instance variable
● A variable which is created inside the class but outside the method is known as an
instance variable. Instance variable doesn't get memory at compile time. It gets
memory at runtime when an object or instance is created. That is why it is known as
an instance variable.
Method
➢ Advantage of Method
★ Code Reusability
★ Code Optimization
❖ Encapsulation
● Encapsulation is a process of wrapping code and data together into a single unit, for
example, a capsule which is mixed of several medicines.
● We can create a fully encapsulated class by making all the data members of the
class private. Now we can use setter and getter methods to set and get the data in it.
● Technically in encapsulation, the variables or data of a class is hidden from any other
class and can be accessed only through any member function of its own class in
which it is declared.
● As in encapsulation, the data in a class is hidden from other classes using the data
hiding concept which is achieved by making the members or methods of a class
private, and the class is exposed to the end-user or the world without providing any
details behind implementation using the abstraction concept, so it is also known as a
combination of data-hiding and abstraction.
❖ Abstraction
● Data Abstraction is the property by virtue of which only the essential details are
displayed to the user. The trivial or the non- essentials units are not displayed to the
user. Ex: A car is viewed as a car rather than its individual components.
● Data Abstraction may also be defined as the process of identifying only the required
characteristics of an object ignoring the irrelevant details. The properties and
behaviors. ors of a of an object differentiate it from other objects of similar type and
also help in classifying/grouping the objects.
● Consider a real-life example of a man driving a car. The man only knows that
pressing the accelerators will increase the speed of car or applying brakes will stop
the car, but he does not know about how on pressing the the a accelerator the speed
is actually increasing, he does not know about the inner mechanism of the car or the
implementation of the accelerator, brakes, etc in the car. This is what abstraction is.
❖ Inheritance
➢ Important terminology:
★ Super Class: The class whose features are inherited is known as superclass(or a
base class or a parent class).
★ Sub Class: The class that inherits the other class is known as a subclass(or a derived
class, extended class, or child class). The subclass can add its own fields and
methods in addition to the superclass fields and methods.
❖ Polymorphism