File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Implementing / Extending

 
Sai Surya
Ranch Hand
Posts: 463
Eclipse IDE Java Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Here is my finding.

class MyClass { }
interface MyInterface { }
public class SampleTest implements MyInterface extends MyClass {

public static void main(String[] args) {
System.out.println("OK");
}
}

gives a compiler error. However, if you say..

public class SampleTest extends MyClass implements MyInterface {

works fine. Does anybody know the reason?

- Surya.
 
Gowher Naik
Ranch Hand
Posts: 643
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Only problem in your code is that
you are implements MyInterface first and then extends MyClass .
In java you should first extend class then you can implements Interface
as shown in code above.
 
wise owen
Ranch Hand
Posts: 2023
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
8.1 Class Declaration
 
Paul Anilprem
Enthuware Software Support
Ranch Hand
Posts: 3670
9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is just a matter of syntax. Java Specification mandates that extends should come before implements.
 
Jay Suttiruttana
Ranch Hand
Posts: 36
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java class cannot extends interface, it can only implements it. Interface can only extends other interface.
 
Srinivas Kalvala
Ranch Hand
Posts: 257
Firefox Browser Hibernate Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

http://jcp.org/en/jsr/detail?id=202
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic