File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Member Variables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Member Variables " Watch "Member Variables " New topic
Author

Member Variables

Nilesh Srivastava
Ranch Hand

Joined: Aug 29, 2003
Posts: 70
Hi,

Can any one tell me , Does interface has member variables. If they, then do all these member variables need to be STATIC AND FINAL. Why is it so? and do these member variables are public(Strictly) or any access modifier will do.

Also, does abstract classes has member variables. DOes all the member variables of abstract class need to be STATIC AND FINAL. Why is it so? and what could be the access modifier of these member variables of abstract class.

Thanks in advance.
Neeraj Dheer
Ranch Hand

Joined: Mar 30, 2005
Posts: 225
Hi!

1. An interface can have member variables. All member variables of an interface are public static and final by default.They cant have any other access modifier.
I think they are static because you cannot instantiate an interface and hence cant have 'object' variables. and so, since they cant be object variables, the only way to use them is to declare them as static.

2. There is no difference in members variables of a 'concrete' class and member variables of an abstract class. so they can be private and need not be static.
Nilesh Srivastava
Ranch Hand

Joined: Aug 29, 2003
Posts: 70
Hi Neeraj,

But what is the use of declaring member variables in Interface. Implementing class can not have acces to those variables and also interface methods can not use these member variables.
Then what is the use of having member variables in an Interface.


Thanks in advance
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Originally posted by Nilesh Srivastava:
Hi Neeraj,

But what is the use of declaring member variables in Interface. Implementing class can not have acces to those variables and also interface methods can not use these member variables.
Then what is the use of having member variables in an Interface.


Thanks in advance

Yes they can. Try it.

You might do this to define a constant available to all classes (whether they implement the interface or not).


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Member Variables
 
Similar Threads
Innerclass
innerclasses
NOTES FROM VELMURUGAN'S SITES:
Restriction on parent class
Inner Classes