Results 1 to 2 of 2
  1. #1
    javastuden's Avatar
    javastuden is offline Senior Member
    Join Date
    Nov 2009
    Posts
    162
    Rep Power
    6

    Default please explain multiple inheritence by an example lot of tutorial i checked but not

    hi any body please explain by pgm what mutiple inheritence is ????????

    and how can i change this pgm to java

    #include <iostream>
    using namespace std;

    class CPolygon {
    protected:
    int width, height;
    public:
    void set_values (int a, int b)
    { width=a; height=b;}
    };

    class COutput {
    public:
    void output (int i);
    };

    void COutput::output (int i) {
    cout << i << endl;
    }

    class CRectangle: public CPolygon, public COutput {
    public:
    int area ()
    { return (width * height); }
    };

    class CTriangle: public CPolygon, public COutput {
    public:
    int area ()
    { return (width * height / 2); }
    };

    int main () {
    CRectangle rect;
    CTriangle trgl;
    rect.set_values (4,5);
    trgl.set_values (4,5);
    rect.output (rect.area());
    trgl.output (trgl.area());
    return 0;
    }

    using interfaces

  2. #2
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    843
    Rep Power
    6

    Default

    1.Make CPolygon,COutput as interfaces.

    2.Dont define any method in the above interfaces in step 1. Just declare the methods
    ex: void set_values (int a, int b);

    3. Make class Rectangle to implement the above interfaces like this below:
    class CRectangle implements CPolygon, COutput {
    implement the interface methods here.
    }

    4. For CTriangle also do the same thing as above.

    5. Finally create an object for the classes and call the methods.



    Still,if you are not clear go thru sun site.... always better.
    Ramya:cool:

Similar Threads

  1. radio button checked by default
    By whiteasshweta in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 07-06-2009, 02:11 PM
  2. Getting around inheritence
    By nick2price in forum New To Java
    Replies: 3
    Last Post: 01-18-2009, 07:48 AM
  3. Replies: 1
    Last Post: 11-18-2008, 05:48 PM
  4. [SOLVED] Problem with code - inheritence
    By yalla in forum New To Java
    Replies: 1
    Last Post: 03-30-2008, 07:11 AM
  5. Checked Exception
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-18-2007, 07:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •