This question already has an answer here:
HOW TO WRITE A JAVA PROGRAM BY USING INTERFACE BY DECLARING IT PUBLIC
For instance:
import java.io.*;
import java.util.*;
interface MyfirstInterface
{
public String helloz="HELLO..FRIENDS";
public void Sayzhello();
}
public class implementor implements MyfirstInterface
{
public void Sayzhello()
{
System.out.println(MyfirstInterface.helloz);
}
public static void main(String args[])
{
implementor MyfirstInterface=new implementor();
MyfirstInterface.Sayzhello();
}
}
//the given program shows output :HELLO..FRIENDS
//while if by using public as like this:
import java.io.*;
import java.util.*;
public interface MyfirstInterface
{
public String helloz="HELLO..FRIENDS";
public void Sayzhello();
}
public class implementor implements MyfirstInterface
{
public void Sayzhello()
{
System.out.println(MyfirstInterface.helloz);
}
public static void main(String args[])
{
implementor MyfirstInterface=new implementor();
MyfirstInterface.Sayzhello();
}
}
it shows like this implementor.java:3: error: class MyfirstInterface is public, should be declared in a file named MyfirstInterface.java public interface MyfirstInterface ^ 1 error how can the error be rectified
Aucun commentaire:
Enregistrer un commentaire