Four building blocks of Object oriented programming language

Four building blocks of Object oriented programming language

Java is an object oriented programming language just like C++,small talk and python.
An OOP language follows four basic rules:
*Inheritance
*Encapsulation
*Polymorphism
*Abstraction

*Inheritance: The ability of a language to reuse previously written code and add further functionalities to the previously written code.
How we use it in Java: BY EXTENDING CLASSES. Each child class inherits the functions and member variables from the parent class without even writing the whole code.
*Encapsulation: The ability of a language to hide the important and private data and encapsulate into an single unit called "CLASS".
How we use it in Java: By creating classes the data wrapped inside it and can only be accessed using the object(unless it is static data).
*Polymorphism: The ability of a language to create a method with same name but multiple arguments each method do different work on different situation.
How we use it in Java:By method overriding Base class method in the child class.The child class can return the object of the base class.
*Abstraction: The ability of a language to hide the inner work done by the language from the user and show only the core work required.
How we use it in Java: By creating abstract classes and Interfaces that contains only the core(Abstract) methods required by the extending classes.

Why do we needs OOPs concept?

  • Because it performs reusability of Code that is previously written
  • Because it concentrate on data rather than the algorithm to be performed.
  • Because you can protect data from external sources by making the class private or final.
  • Because it performs abstraction of data.
  • Because it is possible to add some code to the previously written code for more functionality.

Comments

Popular posts from this blog

Exceptions and exceptional handling

Lists in java