This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Static and Instance variables/Methods in interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Static and Instance variables/Methods in interface" Watch "Static and Instance variables/Methods in interface" New topic
Author

Static and Instance variables/Methods in interface

Harikrishna Gorrepati
Ranch Hand

Joined: Sep 23, 2010
Posts: 422
Hi,

Please advice why we can define only static variables & instance methods but we cannot define static methods & instance variables in an interface?

Thanks


OCPJP 6.0-81% | Preparing for OCWCD
http://www.certpal.com/blogs/cert-articles | http://sites.google.com/site/mostlyjava/scwcd |
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

static methods & instance variables in an interface


An interface is meant to be a contract that is to be followed by a sub class. A contract is meant to be something like a rosetta stone which classes can look up to, to make their own interpretation of what that contract should do.

Static methods cannot be 'overridden' as such, so inheritance would not work. Instance variables do not make sense since there is only one interface. You cannot instantiate an interface, so there is no question of using instance variables.


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
 
 
subject: Static and Instance variables/Methods in interface
 
Similar Threads
Difference b/w abstract interface and Ordinary interface
Variables in interfaces
Restriction on Constants
Interface and abstract
Non-final member variables in interfaces