Results 1 to 15 of 15

Thread: help

  1. #1
    Sayed is offline Member
    Join Date
    Jan 2008
    Posts
    18
    Rep Power
    0

    Smile help

    one class can implement multiple interfaces but it can't extend two calsses why??????
    Last edited by Sayed; 04-03-2008 at 11:32 AM.

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  3. #3
    Sayed is offline Member
    Join Date
    Jan 2008
    Posts
    18
    Rep Power
    0

    Default

    i want the exact reason for that??..what will be the problem if one class extends multiple calsses directly...one class can implement multiple interfaces directly right...

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  5. #5
    Sayed is offline Member
    Join Date
    Jan 2008
    Posts
    18
    Rep Power
    0

    Default

    Thanks for your respone ......could you please brief me on that????what danger it is????

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Oh dear, say ClassA extend from ClassB and ClassC. Say ClassB has a method sampleMethod() and ClassC has sampleMethod(), which method ClassA should call. Compiler really mess-up with it.

    That's why SUNs' avoid this. So you can simply use interfaces. As I said there is a trick for multiple inheritance also.

  7. #7
    Sayed is offline Member
    Join Date
    Jan 2008
    Posts
    18
    Rep Power
    0

    Default

    Thanks yaar...Thanks a lot for your help...

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  9. #9
    Sayed is offline Member
    Join Date
    Jan 2008
    Posts
    18
    Rep Power
    0

    Default

    But what about interfaces???if two interfaces contains same method compiler won't mess-up...

  10. #10
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  11. #11
    Sayed is offline Member
    Join Date
    Jan 2008
    Posts
    18
    Rep Power
    0

    Default

    yes i tried it...it is not showing any compilation problem but the actual implemented method is not executing...could u please help me on this....

  12. #12
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    What you mean actual implemented method is not executing. I'm not clear with it. Do you have any code with you.

  13. #13
    Sayed is offline Member
    Join Date
    Jan 2008
    Posts
    18
    Rep Power
    0

    Default

    Sorry Its executing it is not showing any problems.

  14. #14
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  15. #15
    Sayed is offline Member
    Join Date
    Jan 2008
    Posts
    18
    Rep Power
    0

    Default

    Please have a look on this code:

    public class Test implements Sample1,Sample2{
    public static void main(String args[]){
    System.out.println("public static void main");
    Test t=new Test();
    t.jen();
    }
    public void jen() {
    System.out.println("Success");

    }

    }

    Interface 1:

    ublic interface Sample1 {

    public void jen();


    }

    Interface:2


    public interface Sample2 {
    public void jen();

    }

Posting Permissions

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