I know we can use define variables in interface and abstract. Can anybody please explain me the actual usage of declaring variables in Interface and Abstract classes. like public interface MyInterface { int x=10; void hello(); } and abstract class { int a = 10; abstract public void myhello(); } Thanks
i'm not real sure about the interface one. however, the abstract class one i have seen and used before. basically it is so any class that extends this abstract parent class can use that variable. if sub1 and sub2 are classes that extend this abstract class then both of them inherit their parents qualities. this really exemplifies the idea of subclassing. i am unclear however on what the interface use would be.
Fields in an interface are implicitly public, static and final. On the other hand, fields in an abstract class could have any access modifier, could be static or not, and final or not.
Won't you please? Please won't you be my neighbor? - Fred Rogers. Tiny ad:
Gift giving made easy with the permaculture playing cards