File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Implementing Interface

 
Rahul Senthil
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the compiler error and in which line does it happen? What is it exactly that you don't understand about the error?
 
Mo Jay
Ranch Hand
Posts: 83
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also you have not put paranthesis for second method in interface.
 
Ninad Kulkarni
Ranch Hand
Posts: 802
Hibernate Linux Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Method implementation in method is not allowed you can place class but not method in method.
bring method implementation out side of main method.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic