Page 299 - COPA VOL II of II - TP -Punjabi
P. 299

IT ਅਤੇ ITES (IT & ITES)                                                                      ਅਭਿਆਸ  1.41.22

            COPA - JAVA ਭਿੱਚ ਚੋਣਿੇਂ ਮੋਡੀਊਲ II ਪ੍ਰੋਗ੍ਾਭਮੰਗ

            JAVA ਭਿੱਚ ਢੰਗਾਂ ਨੂੰ ਓਿ੍੍ਾਈਡ ਕ੍ੋ  (Override methods in JAVA)

            ਉਦੇਸ਼ : ਇਸ ਅਭਿਆਸ ਦੇ ਅੰਤ ਭਿੱਚ ਤੁਸੀਂ ਯੋਗ ਹੋਿੋਗੇ

            •  JAVA ਭਿੱਚ ਓਿ੍ਲੋਡ ਕੀਤੇ ਤ੍ੀਕੇ ਬਣਾਓ ਅਤੇ ਿ੍ਤੋ।


               ਲੋੜਾਂ (Requirements)
               ਔਜ਼ਾ੍/ਉਪਕ੍ਨ/ਯੰਤ੍ (Tools/Equipment/Machines)

               •   ਇੱਕ ਕੰਮ ਕਰਨ ਿਾਲਾ ਪੀਸੀ, ਇੰਟਰਨੈਟ ਕਨੈਕਸ਼ਨ, ਟੈਕਸਟ ਐਡੀਟਰ, ਬ੍ਰਾਊਜ਼ਰ ਅਤੇ ਜਾਿਾ JDK                                    - 1 No. / trainee

            ਿਭਧੀ (PROCEDURE)


            ਟਾਸਕ 1 : JAVA ਿਭੱਚ ਓਿ੍੍ਾਈਡਭੰਗ ਿਭਧੀਆਂ ਬਣਾਓ ਅਤੇ ਿ੍ਤੋ
            1   ਿਭਧੀ ਦਾ ਉਹੀ ਨਾਮ ਹੋਣਾ ਚਾਹੀਦਾ ਹੈ ਜੋ ਪੇਰੈਂਟ ਕਲਾਸ ਿਭੱਚ ਹੈ  3   ਇੱਕ IS-A ਰਭਸ਼ਤਾ (ਿਭਰਸਾ) ਹੋਣਾ ਚਾਹੀਦਾ ਹੈ

            2   ਿਭਧੀ ਿਭੱਚ ਉਹੀ ਮਾਪਦੰਡ ਹੋਣੇ ਚਾਹੀਦੇ ਹਨ ਜੋ ਪੇਰੈਂਟ ਕਲਾਸ ਿਭੱਚ ਹਨ।














                                                        SOURCE CODE
              //Java Program to demonstrate the real scenario of Java Method Overriding
                 //where three classes are overriding the method of a parent class.
                 //Creating a parent class.
                 class Bank{
                 int getRateOfInterest(){return 0;}
              }
                 //Creating child classes.                                 Fig 1
                 class SBI extends Bank{
                 int getRateOfInterest(){return 8;}
              }
              class ICICI extends Bank{
              int getRateOfInterest(){return 7;}
              }
              class AXIS extends Bank{
              int getRateOfInterest(){return 9;}
              }
              //Test class to create objects and call the methods
              class Test2{
              public static void main(String args[]){
              SBI s=new SBI();
              ICICI i=new ICICI();
              AXIS a=new AXIS();
              System.out.println(“SBI Rate of Interest: “+s.getRateOfInterest());
              System.out.println(“ICICI Rate of Interest: “+i.getRateOfInterest());
              System.out.println(“AXIS Rate of Interest: “+a.getRateOfInterest());
              }
              }
                                                                                                               285
   294   295   296   297   298   299   300   301   302   303   304