I have a strange problem i don't know if i miss something. Here is my code
public interface Book{
}
public class MyBook implements Book
{
}
public static void main(String[] args)
{
Book b = new MyBook(); // compiler error: Type mismatch ....
}
Can somebody explains to me is th开发者_如何学JAVAis really a compiler error or just my eclipse is acting weird?
Thanks,
Your main method is not in a class, try putting it inside a class.
Also make sure to have only one public class per Java file.
I think after implementation of interface you can make object of class that implemented interface so make the object of class "MyBook"
Sorry, there is another interface of exact same name that is in the imported statement that is causing the problem. Thanks.
精彩评论