Wednesday 20 July 2011

concepts with overriding { private / final / static }

look java is famous for its topic inheritance ... and inside inheritance there is a most important topic called overriding .

if you search for  " overriding " in dictionary than the meaning is "Having superior's power "
so every thing in this text is related with this meaning now how ...

lets start ....
                 basically you can override anything from your parent ... but do you think that if parent does not allow you to override this than you can override those things ...
no ... is the answer .
but why no is the answer .
i will explain u why no is the answer .

if you know something about final , static ,private than this text is good for you otherwise go home and take a rest , and open kathy for java .
----------------------------------------------------------------------------------------------------------------------
final is a thing , which is declared as final . so it you can not override this method . but why , think that override means , a car has a gear_method ( ) , if you say that i want 6 gears in my car than ok ..you are changing it ... and making this method suitable for u .
and if i say that the value of PI in maths is 3.14 than can you change it .. no now you can not change it . but you can use it like " 3.14*r*r  " so this is the term final ..

means overrides means - change { but final cant change }
-----------------------------------------------------------------------------------------------------------------------
private is a thing where you define a signature for the thing ... so do you think that if you declare anything after it you can change it . answer is " long  no " . and private is a thing contains its signature for the whole class .. but not for inherited class ... the inherited class does not know that there is any method . because the scope of privte is only visible inside the class ..

means private looks like overrided but every private has a unique signature . so the answer is no private is never inherited
-----------------------------------------------------------------------------------------------------------------------
now the most confusing term static ...

take it easily and create the defination of static in your mind ..that static is a class type ... means visible to whole class as a single entity ... so when i am saying that visible to class means to only that class .
now ... static is also same as private in look and feel ... but deifferent in working ... it basically work on static binding or in compile time binding .. means it is necessary also .. why take this example .

Class_name     ob_name   =   new   Class_name   (  ) ;
      |
      |
      |______________________ so this class name is in use in static or compile time binding ..
but why ... so i am saying that it is visible to only that class ... and this thing is only provided by this thing ... because in the end of assigning reference you have to declare its  type ...

after this name ... is you access the method with overridden syntax than it will go to               class_name.method( );    so i think thats enough for basics related with final & static & private

No comments: