A blog for computer science passionates.

Monday, 27 January 2020

More Object Oriented Programming: A Real world concepts

Hello Friends!!!
Let's discuss some concepts of 😊bject-☺riented Programming. First of all,
What is Object?
  • In simple words, the object is a combination of Data and Functions. It represents a class and class contains data and functions (methods). For example, consider a class of Animals and an object of an animal class is a dog, cat, etc. it has data i.e. a dog has four legs, two eyes and function i.e. the behavior of a dog is barking.
What is the Class?
  • The class is from which object belongs, i.e. in our above example if an object is a dog, it comes from Animal class. Even we can say that the class is a collection of Data and Function and to represent the data and function we need to make an object. 
What are Methods?
  •  The methods, to work on data, manage data and operate these data. For example, if we have the data about the employee of a company such as employee id, name salary and based on that salary want to calculate allowance and total salary of an employee one needs to define a method.
These three are the main pillars of object-oriented programming. Let's discuss more topics about it...

Inheritance: 
As we know that object-oriented programming is based on real-world concepts and in the real world we have different relations. so object-oriented programming also believes in the relationship. So we have this concept of inheritance. In which, we have more than one class and we relate these classes with each other and reuse the attributes. Reusability is the key for OOP. There are different types of inheritance such as,
  • Single-Level
  • Multi-Level
  • Hierarchical
  • Multiple
  • Hybrid
  • Multipath
But, Multiple and Multipath inheritances do not support by Java. As Java works on real world concept and in real world multiple parents are not possible on child or children, in multiple and multipath inheritance work on multiple parent so.
I just want to figure out all the types of inheritance. And it is easy to get.

Fig. Types of Inheritance
Polymorphism:
It is a greek word means Multiple forms of an attribute such as methods or constructor. To build method or constructor in a class with multiple forms we have to follow some rules,
  • Pass different numbers of arguments in a method or constructor.
  • In a method, we can set a different return type of a method.
For example,
int area(int length, int breadth)
double area(int radius)

This is called Method Overloading.
In inheritance, we can achieve Method Overriding. In inheritance, we have two classes parent and child class, in parent class we have one method and we redefine that method with the same syntax is called method overriding.

Abstraction and Encapsulation:
Through abstraction, we can show all the essential elements and in encapsulation, we can hide the necessary data.

We will see all the concepts in detail when we will look at examples, through all these concepts you feel that Java is based on Real-World thus Java is really great and powerful because it works with and on data.
While working with any object-oriented programming we need to think only one thing and it is data.

Hope you enjoy, this and feel these concepts are yours and related to our life somewhere :)

No comments:

Post a Comment