A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
Arduino in Action
this week in the
General Computing
forum!
A special promo:
Enter your blog post or vote on a blogger to be featured in an upcoming Journal
JavaRanch
»
Java Forums
»
Java
»
Beginning Java
Author
variavle declaration in interface
vijay kumarg
Ranch Hand
Joined: Dec 14, 2006
Posts: 105
posted
Jan 04, 2007 06:06:00
0
Is it mandatory to intialize a variable declared in an interface?
Mathias Nilsson
Ranch Hand
Joined: Aug 21, 2004
Posts: 367
posted
Jan 04, 2007 07:28:00
0
Yes! I think they are.
Try comiling a interface with a variable that is not instanciated and you will get a compile error
= expected
SCJP1.4
Peter Chase
Ranch Hand
Joined: Oct 30, 2001
Posts: 1970
posted
Jan 04, 2007 08:52:00
0
You can't declare variables in interfaces. You can only have public static final fields - i.e. constants. These must be given a value within the interface.
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.<br /> <br />#:^P
Jeroen T Wenting
Ranch Hand
Joined: Apr 21, 2006
Posts: 1847
posted
Jan 04, 2007 10:15:00
0
And you shouldn't do that... Effective Java, topic 17.
42
I agree. Here's the link:
http://aspose.com/file-tools
subject: variavle declaration in interface
Similar Threads
How To Call Two Different Classes From the Main Program Using the Same API?
Regarding Interfaces
Writing an Interface
Time Capsule
Home interface or Home Interface stub
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter