मराठी

Show with the help of an example, how the following base classes can be derived in class bill to fulfill the given requirement: - Computer Applications

Advertisements
Advertisements

प्रश्न

Show with the help of an example, how the following base classes can be derived in class bill to fulfill the given requirement: 

class Elect 
   {
      String n; 
      float units; 
      public void setvalue() 
   {
      n = "SOURABH" 
      units = 6879; 
   }
}

class Bill uses data members charge and a member function to calculate the bill at the rate of ₹ 3.25 per unit and displays the charge. Class Elect is inherited by class Bill by using private visibility. 

कोड लेखन

उत्तर

Class elect can be derived in class bill as shown below:

class bill extends elect {
    private double charge;
    public void calc() {
        charge = 3.25 * units;
        System.out.println("Charge = " + charge);
    }
}
shaalaa.com
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
पाठ 8: Encapsulation and Inheritance - EXERCISES [पृष्ठ ४४६]

APPEARS IN

अविचल Computer Applications [English] Class 10 ICSE
पाठ 8 Encapsulation and Inheritance
EXERCISES | Q V. 18. | पृष्ठ ४४६
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×
Our website is made possible by ad-free subscriptions or displaying online advertisements to our visitors.
If you don't like ads you can support us by buying an ad-free subscription or please consider supporting us by disabling your ad blocker. Thank you.