Any Java code as below will lead an error "no interface expected here"
See that, here Person is a class (public class Person) and it inherits an interface (extends Serializable). Note that a class can inherit another class only, not any interface. A class can implement one or more interface only. Serializable is an interface, not a class.
Actually the correct code of the above will be:
Here it is notable that, only an interface can inherit another interface.
A similar type of error is posted at interface expected here
import java.io.Serializable;
public class Person extends Serializable
{
private String firstName;
private String lastName;
//...
}
See that, here Person is a class (public class Person) and it inherits an interface (extends Serializable). Note that a class can inherit another class only, not any interface. A class can implement one or more interface only. Serializable is an interface, not a class.
Actually the correct code of the above will be:
import java.io.Serializable;
public class Person implements Serializable
{
private String firstName;
private String lastName;
//...
}
Here it is notable that, only an interface can inherit another interface.
A similar type of error is posted at interface expected here
0 comments:
Post a Comment