开发者

Compiler error: Type mismatch when assigned interface variable to a class

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜