File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Implementing Interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Implementing Interface" Watch "Implementing Interface" New topic
Author

Implementing Interface

Rahul Senthil
Greenhorn

Joined: May 25, 2009
Posts: 8
The following program is throwing a compiler error.Can anyone correct me?

interface Base
{
boolean m1();
byte m2(short s);
}


class Base2 implements Base
{
public static void main(String[] args){

public boolean m1() {
return true;
}
public byte m2(short s) {
return 2;
}


}
}
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14430
    
  23

What is the compiler error and in which line does it happen? What is it exactly that you don't understand about the error?


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Mo Jay
Ranch Hand

Joined: Feb 16, 2009
Posts: 83
Look where you put the implementation of the methods m1() and m2(), it is inside main() method which is the wrong place.
Place the implementation outside main() method and you should be getting no errors.

Cheers!!
Abhijeet Pathak
Ranch Hand

Joined: Jul 05, 2009
Posts: 33
Also you have not put paranthesis for second method in interface.


I am the one who knows that I don't know anything.
Abhijeet
Ninad Kulkarni
Ranch Hand

Joined: Aug 31, 2007
Posts: 802

Method implementation in method is not allowed you can place class but not method in method.
bring method implementation out side of main method.


SCJP 5.0 - JavaRanch FAQ - Java Beginners FAQ - SCJP FAQ - SCJP Mock Tests - Tutorial - JavaSE7 - JavaEE6 -Generics FAQ - JLS - JVM Spec - Java FAQs - Smart Questions
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Implementing Interface