Inheritance in Java... || Inheritance

Welcome to my blog...✍️
NAMASTE (Hello) ❤🙏❤ to all of the stunning personalities of the Hive community I am fine and healthy and hope that you also stay fine, happy and healthy with your family


I love everyone! Mostly, I share my personal experiences, like how my day went, how I celebrated festivals, and similar things. But now, I am starting something new along with that. Since writing blogs takes a lot of time, I am unable to properly explore things and share them with you. However, every day, I explore one thing: the programming languages I have to work with in my office.

I already have some basic knowledge of HTML, CSS, and JavaScript, along with experience in some frameworks and libraries like Bootstrap, Tailwind, and jQuery. But now, in my first company, I will also have to work with SQL and Java. So, I have decided to share my learning and experiences related to Java and SQL as well.

The first reason for this is that when I learn and read about any concept, repeating and explaining it will help me retain it better. The second reason is that many people on this platform are also working in programming and coding. If I make any mistakes and they notice them, they will correct me in the comments. This will help me improve my learning.

Inhertitance
According to me, the basic meaning of inheritance is passing on methods and properties to the child, which is known as inheritance. If we try to understand it with a real-life example, we can take the simple example of a grandfather, father, and son. How can we relate inheritance to this relationship? If anything belongs to the grandfather, like property, behavior, or reputation—suppose the grandfather was very popular and had a good face value—then that reputation is also passed on to the father. Similarly, for the son, the property, behavior, and all the things the father inherited from the grandfather are later passed on to him. In the same manner, inheritance also works in programming.

In the above context, we have seen the definition of inheritance by taking the reference of a real-life example. Now, we have to think about why we need this in programming.

To understand it more clearly, let's take only the reference of a father and son. Suppose the father built a house and arranged it according to all the needs and requirements he had at his time. For example, at that time, if someone had a bicycle and a bike, that was sufficient for them. So, he arranged the things according to himself.

image.png

Now, after some time, that house and all the things present in that house are passed on to the children. The child does not belong to the 90s. He needs some extra things. For example, now we need a car. He needs to modify his house according to his needs.

image.png

But it is not required to create the house again or buy the things that were already present in that house. He should only worry about the things he wants. So, he can add some things according to his needs while the previous things remain the same.

image.png
OUTPUT
image.png

Similarly, in programming, for adding functionalities, the whole code is divided into different classes. Each class performs a different role. Suppose, for example, in WhatsApp, there is a payment option that allows you to pay anyone, just like you can pay anyone with the help of PhonePe.

Now, after some time, due to some requirements, they need an extra feature in that payment technology. So, for adding a single add-on to the payment, they should not have to change all the code previously written for payment.

They will simply create another class, suppose VersionUpgrade. In that VersionUpgrade class, they will inherit the Payment class, which contains all the payment logic. They will then simply add the new feature they want.

So, this is how inheritance works. It takes all the previous functionalities and adds the new ones. It makes the code easy to maintain. If some logic is already written and working properly, you do not have to write that logic again and again. This reduces the code size and also enhances the speed of the application.

According to this context few things should be Important to mention show I am mentioning that show I am mentioning that

  • To inherit parent class in child class you need to use the keyword extends Which is a predefined keyboard Which is a predefined keyboard
  • JVM stands for Java virtual machine. It always start the execution of the program from the main method. So for that reason, It is required to use public before declaring the main method.
  • The code written in Java is platform-independent. This means you can write code in any machine, and you can run that code in any machine, because of its byte code feature. It will convert. the code into bytecode and the bytecode will execute in the system according to the jvm presented inside that system.

images.png

✍️✍️
✒️DeviceSmartphone
✒️ModelVivo Z1 Pro
✒️Pixels32 Mp
✒️CountryINDIA
✒️StateMadhya pradesh

A SPECIAL THANKS TO
@indiaunited @spydo @sanjeevm @visionaer3003 @bhattg

Please Do Follow them for their great work and Thank you for your regular support 😍

images.png

THANKS FOR GIVING YOUR VALUABLE TIME TO THIS POST
  • LIKE❤️
  • COMMENT🖋
  • SHARE🔀
> Your Comments and Suggestions are valuable 


0
0
0.000
0 comments