aspose file tools*
The moose likes Beginning Java and the fly likes interface extending a an abstract class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "interface extending a an abstract class" Watch "interface extending a an abstract class" New topic
Author

interface extending a an abstract class

Krishna Chaitanya Reddy Kuninti
Greenhorn

Joined: May 29, 2007
Posts: 13
Hi all,

Syntactically , can an interface extend(inherits) a pure abstract class (that is an abstract class containing all abstract methods)?.

regards,
Krishna
dhwani mathur
Ranch Hand

Joined: May 08, 2007
Posts: 621
well!!!
you if want to check it syntacticlly if we can extend or not? than why dont you try this,please let me know as well....
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3344

well, thats a good question.

Lets just think before we ink..

If we had understood the concepts behind the interfaces and abstract classes and what they are actually, lets have some questions here..

  • Can a pure abstract class (as OP[Original Poster] quoted) be treated as an interface? (though they both mean to represent the same)
  • If at all, under what circumstances we can have it? We should have some clear separation right!


  • If the answer for question 1 above is "Yes", then we should have had a clear distinction on the scenarios of how and when it can be treated as such.

    But, actually they are NOT equal. The reasons behind them are :

  • The structure wise they both are treated different.
  • The interface does not come under the inheritance hierarchy whereas an abstract class does


  • Now, can you come to a conclusion? or the result expected out of compiling such a program?


    The compilation of above program gives the following error



    Hope this helps!
    [ July 30, 2007: Message edited by: Raghavan Muthu ]

    Everything has got its own deadline including one's EGO!
    [CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
    dhwani mathur
    Ranch Hand

    Joined: May 08, 2007
    Posts: 621
    Hey Raghavan

    You have mentioned that an interface cannot
    be instantiated but an abstract class can be.....


    To what i can say is abstract class can never
    be instantiated as per i know,we can just inherit the
    methods of abstract class that is for it is abstract
    isnt it?
    Raghavan Muthu
    Ranch Hand

    Joined: Apr 20, 2006
    Posts: 3344

    Thanks for correcting dhwani. I was just intended to say the "inheritance hierarchy" but while the way i was typing, it got a typo that "instantiate". Its edited now.

    Thank you.
    dhwani mathur
    Ranch Hand

    Joined: May 08, 2007
    Posts: 621
    You are Welcome Raghavan!!!
    Krishna Chaitanya Reddy Kuninti
    Greenhorn

    Joined: May 29, 2007
    Posts: 13
    Hi all,

    I tried to write an interface that extends(inherits) a pure abstract class and find some facts.

    1) An Interface can extend(inherits) only another interface.

    2)An Interface can not extend(inherits) any other class, abstract class with non-abstract methods and pure abstract class(abstract class having all abstract methods).

    In other way, there can be a super interface for an interface but there can not be a superclass for an interface.
    Krishna Chaitanya Reddy Kuninti
    Greenhorn

    Joined: May 29, 2007
    Posts: 13
    Hi all,
    Hi all,

    When I tried to write an interface that extends(inherits) a pure abstract class, I have found the following facts.

    1) An Interface can extend(inherits) only another interface.

    2)An Interface can not extend(inherits) any other class, abstract class with non-abstract methods and pure abstract class(abstract class having all abstract methods).

    In other way, there can be a super interface for an interface but there can not be a superclass for an interface.

    regrads,
    Krishna
    Peter Chase
    Ranch Hand

    Joined: Oct 30, 2001
    Posts: 1970
    Trial and error is one way to find out the answer to these questions, but it can lead to misunderstandings and bad assumptions.

    The best way to find out what is allowed in the language is to read the Java Language Specification, which is available on-line for free. For instance, here is the section on interfaces, which tells you what is and is not legal.

    By the way, while what you called a "pure abstract class" (a class with no concrete methods) is legal in Java, it is rarely useful. Why would you not want to use an interface? Perhaps you have come from C++, where interfaces are not a separate kind of thing and are instead represented as "pure-virtual classes".
    [ July 31, 2007: Message edited by: Peter Chase ]

    Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
    Krishna Chaitanya Reddy Kuninti
    Greenhorn

    Joined: May 29, 2007
    Posts: 13
    Hi all,

    Peter, thanks for your advice and information.

    regards,
    Krishna
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: interface extending a an abstract class