File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Implementing Interface" Watch "Implementing Interface" New topic

Implementing Interface

Rahul Senthil

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: 15080

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.

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.
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
I agree. Here's the link:
subject: Implementing Interface
It's not a secret anymore!