OVERRIDING Concept in JAVA

0

Using this we will create the same name method from base class to derived class only functionality will be different.



Overriding will be used to modify the internal functionality without changes on Actual Class.

No need to keyword in JAVA only method name and respective parameters should be the same.


class  Billing
{
    int amt;
    float total;
    void accept(int amt)
     {
        this.amt=amt;
     }
     void bill(int p)
     {
       total = this.amt+p;
     }
     void display()
     {
        System.out.println(total);
    }

}
class Billinggst extends Billing
{
    void bill(int p)
    {
        total = amt-(amt*.18F)+p;
    }

   public static void main(String args[])
   {
         Billinggst obj = new Billinggst();
         obj.accept(1200);
         obj.bill(700);
         obj.display(); 
   }  

}







Post a Comment

0Comments

POST Answer of Questions and ASK to Doubt

Post a Comment (0)