This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Public Interface Problem

 
vijay malhotra
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 464
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic