aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Public Interface Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Public Interface Problem" Watch "Public Interface Problem" New topic
Author

Public Interface Problem

vijay malhotra
Greenhorn

Joined: Nov 26, 2000
Posts: 26
The following code does not compile and give the following error
Error :-
-----
m1.java:1: class h1 is public, should be declared in a file named h1.java
public interface h1
^
1 error
Code:-
-----
public interface h1
{
void callme();
}
public class m1 implements h1
{
public void callme()
{
System.out.println("Hello");
}
public static void main(String args[])
{
m1 m = new m1();
m.callme();
}
}
Can't the interfaces being declared public ? This entire code is
in file m1.java.
Ragu Sivaraman
Ranch Hand

Joined: Jul 20, 2001
Posts: 464
Originally posted by vijay malhotra:
The following code does not compile and give the following error
Error :-
-----
m1.java:1: class h1 is public, should be declared in a file named h1.java
public interface h1
^
1 error
Code:-
-----
public interface h1
{
void callme();
}
public class m1 implements h1
{
public void callme()
{
System.out.println("Hello");
}
public static void main(String args[])
{
m1 m = new m1();
m.callme();
}
}
Can't the interfaces being declared public ? This entire code is
in file m1.java.


Yes interface can be public... but they have to be in their own source file
Remember no two top-level public in a single java source file
Hope it helps you
Ragu
 
Don't get me started about those stupid light bulbs.
 
subject: Public Interface Problem