OBJECT ORIENTED CONCEPTS

OOPS CONCEPTS 





The popular object-oriented languages are Java, C#,php, Python,c++ etc.

The main aim of object-oriented programming is to implement real-world entities.


 Java is object oriented programming language.

Object oriented programming features-

1) inheritance

2) encapsulation

3) abstraction

4) polymorphism

   - run time polymorphism

   - compile time polymorphism

5) association

6) composition

7) aggregation.



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.


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.


Abstraction


Hiding internal details and showing functionality is known as abstraction. For example phone call, we don't know the internal processing.and ATM GUI screen.

In Java, we use abstract class and interface to achieve abstraction.

Advantages of abstraction -

1) security - we are not showing our internal implementation.

2) we can able to perform any type of changes .

3) it improves maintainabilityof the application


Encapsulation



Binding (or wrapping) code and data together into a single unit are known as encapsulation. For example, a capsule, it is wrapped with different medicines.

A java class is the example of encapsulation. Java bean is the fully encapsulated class because all the data members are private here.


Encapsulation = data binding + Abstraction.


Advantages of encapsulation

1) we can achieve security.

2) enhancement become easy

3)it improves maintainability of application.


Inheritance

When one object acquires all the properties and behaviors of a parent object, it is known as inheritance. It provides code reusability. It is used to achieve runtime polymorphism.


By using extends keyword We can achieve inheritance .

Whatever method parents has ,by default available to the child.

JAVA doesn't support multiple inheritance.

Why multiple inheritance not supported by Java?

Consider a case where class B extends class A and Class C and both class A and C have the same method display().

Now java compiler cannot decide, which display method it should inherit. To prevent such situation, multiple inheritances is not allowed in java.


Polymorphism



If one task is performed in different ways, it is known as polymorphism. For example: to convince the customer differently, to draw something, for example, shape, triangle, rectangle, etc.

In Java, we use method overloading and method overriding to achieve polymorphism.

Another example can be to speak something; for example, a cat speaks meow, dog barks woof, etc




Comments

Popular posts from this blog

Arrays programms