Thursday, 5 January 2012

What is Inheritance?

We have to know the inheritance concept good enough to start programming. Guys its simple : One object persisting the properties of another object , I mean I have some of my dad qualities that’s it. Main things we have to make a note is Parent Class,Child Class, super keyword and this pointer. As the name suggests, inheritance means to take something that is already made. It is one of the most important feature of Object Oriented Programming. Someone has written it and we just use it in our programming by just extending the class with the extend keyword. Concept : The concept of inheritance is used to make the things from general to more specific e.g. When we hear the word vehicle then we got an image in our mind that it moves from one place to another place it is used for traveling or carrying goods but the word vehicle does not specify whether it is two or three or four wheeler because it is a general word. But the word car makes a more specific image in mind than vehicle, that the car has four wheels . It concludes from the example that car is a specific word and vehicle is the general word. If we think technically  to this example then vehicle is the super class (or base class or parent class) and car is the subclass or child class because every car has the features of it's parent (in this case vehicle) class. Car is derived from vehicle, so vehicle is parent and car is child. KEYWORDS USED IN INHERITANCE : SUPER : THIS KEYWORD IS USED WHEN WE WANT TO USE A SUPER CLASS IN SUBCLASS IN SIMPLE WORDS, SOME ONE HAS WRITTEN A CODE AND KEPT IN A FILE AND WE WANT TO USE IT. WHAT WE DO IS WE JUST WRITE A CLASS AND EXTEND THE SUPER CLASS. LIKE CLASS MYNAME EXTEDS SUPERNAME WHAT IS SUPER KEYWORD ? The super is java keyword. As the name suggest super is used to access the members of the super class.It is used for two purposes in java. e.g. Suppose class A is the super class that has two instance variables as  int a and float b. class B is the subclass that also contains its own data members named a and b. then we can access the super class (class A) variables a and b inside the subclass class B just by calling the following command. SUPER.MEMBER;

No comments:

Post a Comment