Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

polymorphism in oop

poly means        ( many )
morphism  mean    ( Form )
polymorphism      ( many forms )

example of polymorphism :::
    1. water has many forms  ( solid , liquid , gas )
    2. shapes has many forms ( circle , rectangle , square )
    3. sound has many forms  ( loin , male , female  )


types :::
    1. compile time polymorphism  ( static polymorphism )   ( handle by compiler )
    2. run time polymorphism      ( dyanmic polymorphism )  ( handle by jvm )


achieve by :::
    1. compile time polymorphism   ( method overloading )
    2. run time polymorphism       ( method overridding )


cases :::

    method overloading :::
        "1. if we pass character it will call int due to ( automatic promotion )
        2. if we pass character it will call object if it is in the arguments 
        3. if number of arguments (same datatype like in promotion) is large than no automatic promotion
        4. main method can be overload
        5. changing the return type cannot overload"

    method overridding :::
        ok ::
            "1. return type (covarent return type) change say ho sakta ha
                (we can provide parent in parent return type and child ma return type parent ki child honi chiya)
            2. access modifier 
                (child overridding access modifier is greater than parent overridding method)
            3. overridding and exception handling 
                (if parent class overridding method not throw exception child class only throw check exception)
                (if parent class overridding method throw exception child class only throw same as parent,samelevel,chlid exception)
            4. to inherted abstract class its methods also to be inherted
            5. implement ka sab methods ko run karna paray ga
            6. synchronized/strictfp can also run "

        donot ::
            "1. final methods
            2. static method
            3. private method"
        

    automatic promotion :::
        "byte - short - int 
        char - int 
        int - float , double , long
        float - double
        long - float , double
        int - float - boolean"

    object :::
        "object is the parent class of all the classes
        ( the compile perfer child class to call it first )"

    varargs :::
        "used for multiple arguments
        ( it has least property if no method match than it will run )"


difference method overloading and overridding :::
    method overloading :::
        1. same name 
        2. same class 
        3. different arguments ( no.of arg , type of arg , seq of arg )

    method overridding :::
        1. same name 
        2. different class
        3. same arguments ( no.of arg , type of arg , seq of arg )
        4. is-a relationship ( inheritance )


achieve by programing :::

    method overloading :::
            class test {
                void show (){
                    sout("1")
                }
                void show(int a){
                    sout("2")
                }
                psvm(String[] args){
                    test test = new test();
                    test.show();
                }
            }

    
    method overridding  :::
            class test {
                void show(){
                    sout("1")
                }
            }
            class xyz extends test {
                void show(){
                    sout("2")
                }
                psvm(String[] args){
                    test test = new test();
                    test.show()              -- it will call its own method

                    xyz xyz = new xyz();
                    xyz.show()               -- it will call its own method
                }
            }


invoking the overridding method from subclass :::
    by using "super" keywoard we can run the parent overridding method

        class test {
            void show(){
                sout("1")
            }
        }
        class xyz extends test {
            void show(){
                super.show()
                sout("2")
            }
            psvm(String[] args){
                test test = new test();
                test.show()              -- it will call its own method

                xyz xyz = new xyz();
                xyz.show()               -- it will call its own method
            }
        }
Comment

PREVIOUS NEXT
Code Example
Java :: is a and has a relationship in java 
Java :: java is list ordered 
Java :: hollow pyramid star pattern in java 
Java :: java reverse string 
Java :: java standard exceptions 
Java :: different types of variables in java 
Java :: java method reference 
Java :: convert char array to set in java 
Java :: java hashcode 
Java :: android textview center align text programmatically 
Java :: for java 
Java :: android java get value from listview item 
Java :: default parameters in java 
Java :: how to make a dictionary in java 
Java :: regex pattern for bank cards validation 
Java :: java string literals 
Java :: rock paper scissor in java 
Java :: convert array of char to string java 
Java :: Imageview on the bottom left of Imageview android anchor 
Java :: writing values in 2d array java 
Java :: java 2 decimals 
Java :: comment générer un nombre aléatoire en java 
Java :: spring log info 
Java :: java how to fill an array 
Java :: save bitmap file for share on android 10 
Java :: how to strip spaces in java using split with other delimiters 
Java :: java methods 
Java :: is it possible to quick sort a string in java 
Java :: java string join 
Java :: spring convert page to list 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =