Originally posted by Zack Snyder:
I just wrote a very simple small piece of code to test concepts abt interfaces.
public abstract interface Bounce
{
int v = 10;
}
class Ball implements Bounce
{
int x = v*2;
System.out.println("x : " +x);
}
And i get the following error:
c:\java\Ball.java:12: <identifier> expected
System.out.println("x : " +x);
^
1 error
Whats wrong?
cmbhatt
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
but after including 'p.s.v.m' statement, i am getting compiler error, however the program runs giving expected output ' x : 20 '.
cmbhatt
cmbhatt
Originally posted by Ram Gopal:
ok... with this modification i am getting no error...
but what explains the earlier compile time error..
i mean the syntax was correct...
1) interfaces should be 'public' 'abstract'
2) class implements an interface
3) interface constants were implicitly 'public static final'
what surprised me that Bounce was an interface & Ball was a class, yet the error said that the class Bounce is public..
cmbhatt
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Originally posted by nik arora:
Hi Chandra,
What you specified in code was correct but i have a doubt.Look at the following code
public abstract interface Bounceable
{
}
public class Bounce implements Bounceable
{
}
Will the above code compile?
cmbhatt
Originally posted by Chandra Bhatt:
NO!
4- Per source file there must not be more than one public class or interface. It means one public class or public interface; but there can be any number of non public class and interfaces in a .java source file.
cmbhatt
Originally posted by Ram Gopal:
yeah absolutely right...
infact i just tried to declare interface as private and it gives an error
"Bounceable1.java:1: modifier private not allowed here"
so i guess we can use ONLY public modifier for an interface...
cmbhatt