• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Usage of members in Interface and Abstract

 
author and deputy
Posts: 3150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
interface variable is public static final
so,it can access from every class that implement it
(see interface Connection in for example of usage)
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic