wood burning stoves
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Implementing / Extending Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Implementing / Extending " Watch "Implementing / Extending " New topic

Implementing / Extending

Sai Surya
Ranch Hand

Joined: Feb 08, 2006
Posts: 463

Hi All,

Here is my finding.

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

public static void main(String[] args) {

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

public class SampleTest extends MyClass implements MyInterface {

works fine. Does anybody know the reason?

- Surya.

Sai Surya, SCJP 5.0, SCWCD 5.0, IBM 833 834
http://sai-surya-talk.blogspot.com, I believe in Murphy's law.
Gowher Naik
Ranch Hand

Joined: Feb 07, 2005
Posts: 643

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

Joined: Feb 02, 2006
Posts: 2023
8.1 Class Declaration
Paul Anilprem
Enthuware Software Support
Ranch Hand

Joined: Sep 23, 2000
Posts: 3635
It is just a matter of syntax. Java Specification mandates that extends should come before implements.

Enthuware - Best Mock Exams and Questions for Oracle Java Certifications
Quality Guaranteed - Pass or Full Refund!
Jay Suttiruttana
Ranch Hand

Joined: Aug 17, 2006
Posts: 36
Java class cannot extends interface, it can only implements it. Interface can only extends other interface.
Srinivas Kalvala
Ranch Hand

Joined: Oct 20, 2005
Posts: 257


I agree. Here's the link: http://aspose.com/file-tools
subject: Implementing / Extending
It's not a secret anymore!