Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Implementing Interface

 
Rahul Senthil
Greenhorn
Posts: 8
  • 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
Posts: 15359
39
Android IntelliJ IDE Java Scala Spring
  • 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
  • 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
  • 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
Java Linux
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic